doushijia5684 2013-03-02 23:31
浏览 42

如何访问嵌套在函数内的类内的变量[关闭]

Very new to classes in PHP, How can I access the variable from within the class inside a function?

 //how can I echo the value of the title variable outside the class?
 echo $title; 
 class myClass {

  function form() {
      echo '<input type="text" value="'.$title.'" />';
   }

 }   

Thanks for the help

  • 写回答

3条回答 默认 最新

  • doute7910 2013-03-02 23:34
    关注
     class myClass {
     public $title;     
      function form() {
          echo '<input type="text" value="'.$this->title.'" />';
       }
    
     }  
    

    You said, how to access within a class, but in your example, your property/variable was not inside the class. Just sayin..

    评论

报告相同问题?