当前位置:Gxlcms > PHP教程 > php的null

php的null

时间:2021-07-01 10:21:17 帮助过:15人阅读

为什么运行一下代码不报warning或者notice

$data = null;

var_dump($data['name']);

结果:

null

回复内容:

为什么运行一下代码不报warning或者notice

$data = null;

var_dump($data['name']);

结果:

null

这是一个很有意思的问题, 查了查资料, php.com上有人提出过

https://bugs.php.com/bug.php?id=68110
https://bugs.php.com/bug.php?id=54556

在后面的那页链接里看到了鸟哥@Laruence, 我想能最好深入解答这个问题, 就是他了.

$arr = false;
var_dump($arr['foo']['bar']['baz']); // NULL

php手册上问题原文:


I added this bug to bugs.php.com
(https://bugs.php.com/bug.php?id=68110) however I made tests with
php4, 5.4 and 5.5 versions and all behave the same way.

This, in my point of view, should be cast to an array type and throw
the same error.

This is, according to the documentation on this page, wrong.

From doc: "Note: Attempting to access an array key which has not been
defined is the same as accessing any other undefined variable: an
E_NOTICE-level error message will be issued, and the result will be
NULL."

你检查下php.ini的配置呢 或者在输出前加error_reporting(-1);试下呢

Up up..

人气教程排行