doujiyan0971
2014-04-18 03:05 阅读 46
已采纳

PHP原始数据类型属性

Why is it that getting a property of any PHP primitive data type does not trigger an error or warning?

Tried this on php 5.3.28:

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

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

No errors or warnings were triggered.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dtttlua7165 dtttlua7165 2014-04-18 03:10

    You don't have any error reporting enabled. When I run your code I see this:

    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
    

    Try running the code again, but add error_reporting(E_ALL); as the first line

    点赞 评论 复制链接分享

相关推荐