I wanna know how php interprets this code. Is it something of syntax error or matching priorty? I appreciate any help.
Code:
// php 5.3
class Man {
var $arr = array('name'=>'me');
}
$key = 'name';
$man = new Man();
echo $man->arr['name']; // output me
echo $man->$key['name']; // output nothing along with warning and notice
// output:
PHP Warning: Illegal string offset 'name' in php shell code on line 1
PHP Notice: Undefined property: Man::$n in php shell code on line 1
$keyisname. There is no propertynameinManclass. That's why there's a warning. Also the above looks like PHP 4 syntax. please try to avoid it, your co-workers will be grateful.Notice: Undefined property: Man::$name): 3v4l.org/o5sgS