doujiyan0971 2014-04-18 03:05
浏览 56
已采纳

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 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作