I found what is mystery action of php. look this program,
<?php class Test { var $a = "uho"; function a() { $this->a = "a"; return $this->a; } function b() { $b = $this->a; var_dump($b); } } $w = new Test(); $w->b(); ?>
This prints string(3) "uho". but as follows program prints different result
<?php class Test { var $a = "uho"; function a() { $this->a = "a"; return $this->a; } function b() { $b = $this->a(); var_dump($b); } } $w = new Test(); $w->b(); ?>
you would see answer quickly if you knew about php. Result is string(1) "a", because function a() is called by member method b() but , how about this?
<?php class Test { var $a = "uho"; function a() { $this->a = "a"; return $this->a; } function b() { $b = $this->a(); $c = $this->a; var_dump($c); } } $w = new Test(); $w->b(); ?>
It is result is string(1) "a" Why it so? I wonder this, If you remove $b = $this->a() then program will run according to the expectation. yes it is the one that we hope. I do not know why php run this action, But it looks like what it succeeds the previous value. Will this be a bug of php? Last I write this. you exchange $b = $this->a() and $c = $this->a of last program. If you do so you will know funny thing. I LOVE PHP