为什么获取任何PHP基元数据类型的属性都不会触发错误或警告?
在php 5.3.28:上尝试过
$num = 1;
$str = 'hello';
$arr = array(1,2,3);
$nada = null;
$num->key1;
$str->key2;
$arr->key3;
$nada->key4;
未触发任何错误或警告。
您没有启用任何错误报告。当我运行你的代码时,我看到这个:
PHP Notice: Trying to get property of non-object in /home/5BSpSI/prog.php on line 8
PHP Notice: Trying to get property of non-object in /home/5BSpSI/prog.php on line 9
PHP Notice: Trying to get property of non-object in /home/5BSpSI/prog.php on line 10
PHP Notice: Trying to get property of non-object in /home/5BSpSI/prog.php on line 11
再次尝试运行代码,但将error_reporting(E_ALL);
添加为的第一行