|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #37676 using Array access operator [] on boolean variable does not show Notice
Submitted: 2006-06-02 11:21 UTC Modified: 2019-07-10 12:19 UTC
Avg. Score:4.0 ± 1.1
Reproduced:22 of 22 (100.0%)
Same Version:14 (63.6%)
Same OS:12 (54.5%)
From: tgross at m-s dot de Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: * 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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: tgross at m-s dot de
New email:
PHP Version: OS:


 [2006-06-02 11:21 UTC] tgross at m-s dot de
When trying to access an array using an undefined offset, PHP displays an Notice.

However, when you access a boolean variable with any combination of the array operator [], PHP just returns NULL and displays no error message.

Reproduce code:
error_reporting (E_ALL);
$a = false;

var_dump ($a[5]);
var_dump ($a['test'][-3]);

Expected result:
PHP should display a Notice or a Warning.

Actual result:
PHP displays


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-02 11:25 UTC]
Reclassified as feature request.
 [2010-12-20 15:47 UTC]
-Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: Windows XP +Operating System: * -PHP Version: 5.1.4 +PHP Version: *
 [2012-09-29 12:20 UTC] svodev at gmail dot com
The same issue is with NULL values;

$a = NULL;

echo $a['b'];

...and nothing happen
 [2012-09-30 01:06 UTC]
yeah, I remembered there was a similar bug report of this behavior, and I seems 
made a fix for it.

if I remember correctlly, it was merged into master-branch already
 [2013-02-01 20:12 UTC] jason at fuzzystatic dot com
Bug still occurs on a 5.5-dev version.

 [2015-01-09 00:26 UTC]
Still exists in PHP 5.6:

$ php -d error_reporting=E_ALL -r '$x = false; var_dump($x[5]);'
 [2015-01-09 00:41 UTC]
 [2015-10-07 18:20 UTC] codedokode at gmail dot com
Also it silently returns NULL when trying to pass a number as an array: 


$int = 1;


Expected: Error using integer as array
Actual result: NULL

I thing using a scalar value as an array is obviously user's error and it should be reported, e.g. with error message.

Tested in PHP 5.6.7 (Debian), no error message reported. 

The same result if we use float instead of int. The same result if we use resource as array:

$ php -r 'error_reporting(-1);$h = fopen("/etc/passwd", "r"); $x = $h[0];var_dump($x);'
 [2016-07-25 17:35 UTC] dave at mudsite dot com
I attached a PR to this issue.  It attempts to only display an E_NOTICE once for extended failures like:

$a = false;

This should error once.  It will also raise an E_NOTICE for other FETCH_DIM_R opcodes like:

$a = false;
list($b, $c) = $a;

This would have 2 E_NOTICE one for each assignment to $b, and $c.
 [2019-07-10 12:19 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2019-07-10 12:19 UTC]
Will throw a notice in 7.4.
 [2019-08-31 20:12 UTC] glen at pld-linux dot org
Trying to find RFC or PR or commit related to this bug...

- from
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Oct 21 20:01:28 2019 UTC