php的null

WBOY
WBOY원래의
2016-06-06 20:38:461034검색

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

<code>$data = null;

var_dump($data['name']);
</code>

结果:

<code>null
</code>

回复内容:

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

<code>$data = null;

var_dump($data['name']);
</code>

结果:

<code>null
</code>

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

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

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

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

php手册上问题原文:

<code><?php $a['a'] = null;
$a['b'] = array();

echo $a['a']['non-existent']; // DOES NOT throw an E_NOTICE error as expected.

echo $a['b']['non-existent']; // throws an E_NOTICE as expected
?>
</code>

I added this bug to bugs.php.net
(https://bugs.php.net/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..

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.