开发者

Class variables messing up [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

consider this code :

Class Controller_xyz extends Controller
{
    protected $res=' ';
    public function action_reg()
    {
         $this->res="bla开发者_C百科h";
         $x="blah"
         echo $this->res;
         echo $x;
    }
}

output :

b
blah

why am I not able to change class variable?


You made a typo @

$x="blah" (missing ;)

Working code: http://ideone.com/jmICU

(Controller stripped out)

Please let me know if my answer has worked.


It is NOT class variable but instance variable if you define/access it this way.

Most of the time in PHP, i forget including $ in variable name. Try as

$this->$res = "blah";

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜