PHP原始数据类型属性

时间:2014-04-18 03:05:23

标签: php oop primitive

为什么获取任何PHP原始数据类型的属性不会触发错误或警告?

在php 5.3.28上试过这个:

$num = 1;
$str = 'hello';
$arr = array(1,2,3);
$nada = null;

$num->key1;
$str->key2;
$arr->key3;
$nada->key4;

未触发任何错误或警告。

1 个答案:

答案 0 :(得分:2)

您没有启用任何错误报告。当我运行你的代码时,我看到了:

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);作为第一行