美文网首页
echo a static varible

echo a static varible

作者: 张霸天 | 来源:发表于2017-03-24 08:21 被阅读0次

Some thing that may be obvious to the seasoned PHP programmer, but may surprise someone coming over from C++:


<?php
class Foo
{
$bar = 'Hi There';

public function Print(){
    echo $bar;
}
}
?>

Gives an error saying Print used undefined variable. One has to explicitly use (notice the use of<?php $this->bar ?>):


<?php
class Foo
{
$bar = 'Hi There';

public function Print(){
    echo this->$bar;
}
}
?>


<?php echo $this->bar; ?> refers to the class member, while using $barmeans using an uninitialized variable in the local context of the member function.

相关文章

网友评论

      本文标题:echo a static varible

      本文链接:https://www.haomeiwen.com/subject/dwyxottx.html