Sharing var from one function to the other function in PHP Class

前端 未结 2 993
渐次进展
渐次进展 2021-01-22 15:31

Well, I am not good at scripting, and I am kinda Photoshop guy. I am also new at PHP, so please bear with me. I am currently creating web form generation class which needs to b

2条回答
  •  面向向阳花
    2021-01-22 16:12

    You can define variables inside the class:

    class myclass
     {
    
       public $varname;  // If you want public access
       private $varname2;  // access only for members of this class
       protected $varname3;  // access for members of this class and descendants
    

    and use them in your methods like so:

    echo $this->varname;
    

    if for communication between two functions only, best declare them protected.

提交回复
热议问题