php.net |  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
Votes:2
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: julien at palard dot fr
New email:
PHP Version: OS:

 

 [2012-08-07 14:42 UTC] julien at palard dot fr
Description:
------------
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-08 02:36 UTC] laruence@php.net
const array dereference is only in trunk
 [2012-08-08 07:10 UTC] julien at palard dot fr
laruence@php.net : 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] mike@php.net
-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"]);'
NULL

Seems not right, I'd rather prefer to get, at least, a NOTICE here.
 [2015-06-08 20:50 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2015-06-08 20:50 UTC] cmb@php.net
This is a duplicate of bug #54556.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 08:01:29 2024 UTC