|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62769 Inconsistent notice reporting using []
Submitted: 2012-08-07 14:42 UTC Modified: 2015-06-08 20:50 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: julien at palard dot fr Assigned: cmb (profile)
Status: Duplicate Package: *General Issues
PHP Version: 5.4.5 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
46 + 44 = ?
Subscribe to this entry?

 [2012-08-07 14:42 UTC] julien at palard dot fr
Error reported for invalid [] access seems inconsistent :

echo NULL["bar"] -> Parse error
echo []["bar"]   -> Parse error
$foo = NULL; echo $foo["bar"] -> Fails silently
$foo = [];   echo $foo["bar"] -> Notice: Undefined index
class Bar {} ; $foo = new Bar(); echo $foo["bar"]; -> PHP Fatal error

I whish :
[]["bar"] to trigger Notice: Undefined index
NULL["bar"] to trigger something catcheable with set_error_handler
$foo = NULL; $foo["bar"] to trigger a catcheable Notice.

Test script:
/usr/local/php-5.4.5/bin/php -r 'error_reporting(-1); echo []["bar"];'
/usr/local/php-5.4.5/bin/php -r 'error_reporting(-1); echo NULL["bar"];'
/usr/local/php-5.4.5/bin/php -r 'error_reporting(-1); $foo = NULL; $foo["bar"];'
/usr/local/php-5.4.5/bin/php -r 'error_reporting(-1); $foo = []; $foo["bar"];'
/usr/local/php-5.4.5/bin/php -r 'error_reporting(-1); class Bar {} ; $foo = new Bar(); echo $foo["bar"];'

Expected result:
At least get a Notice on :
$foo = NULL;
echo $foo["bar"];

Actual result:
Fails silently.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-08 02:36 UTC]
const array dereference is only in trunk
 [2012-08-08 07:10 UTC] julien at palard dot fr : Nice for const array dereference :-)

But what about the point of the ticket :

$foo = NULL;
echo $foo["bar"];

that fails silently ?
 [2012-09-04 17:54 UTC] ajf at ajf dot me
Well, according to someone in internals whose name I forgot, NULL[$anything] is 
implicitly NULL. Which I think is rather absurd, personally. I don't see why it's 
not an error.
 [2013-07-30 19:21 UTC]
-Package: Output Control +Package: *General Issues
 [2014-05-28 09:37 UTC] julien at palard dot fr
Also :
$ php -r 'error_reporting(-1); $foo = 0; var_dump($foo["foo"]);'

Seems not right, I'd rather prefer to get, at least, a NOTICE here.
 [2015-06-08 20:50 UTC]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2015-06-08 20:50 UTC]
This is a duplicate of bug #54556.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 18 13:03:34 2021 UTC