Why does this not make a difference between property and variable?

后端 未结 4 1981
旧时难觅i
旧时难觅i 2021-01-21 00:23
class someclass
{
    public $foo = \'abcd\';

    public function __construct($data)
    {
        $this->foo = $data;
    }
    public function doSomething()
    {
         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-21 00:46

    It is correct and it works fine. I ran your code and it always gives me the same. There's no problem you have property $foo and $foo variable in one or multiple functions. It always give me the same answer.

    If $_POST['foo']=test then echo $foo = $_POST['foo']; returns "test", $foo returns "test" and $somethingelse returns "test";

提交回复
热议问题