Class variables messing up [closed]
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";
精彩评论