php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21814 false array keys
Submitted: 2003-01-22 03:30 UTC Modified: 2003-01-22 08:49 UTC
From: philip at cornado dot com Assigned: iliaa (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 4CVS-2003-01-22 (stable) OS: linux
Private report: No CVE-ID: None
 [2003-01-22 03:30 UTC] philip at cornado dot com
One can create a key as integer 0 and access it with key boolean false but one cannot create an array with boolean false as the key.  In otherwords:

$arr = array(false => 'bar');      // array()
$arr = array((int)false => 'bar'); // array(0=>'bar')

$arr = array(0 => 'bar');
print $arr[false];            // bar
print $arr[(int)false];       // bar

This seems inconsistent.  From the documentation:

Using TRUE as a key will evalute to integer 1 as key. Using FALSE as a key will evalute to integer  0 as key.

Please explain the reasoning behind the current behavior.

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-22 08:49 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Aug 15 14:01:27 2024 UTC