php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51677 Multidimensional array returns non-existing value
Submitted: 2010-04-28 06:33 UTC Modified: 2010-04-28 06:49 UTC
From: jasonwyz98 at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.2 OS: Ubuntu 9.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jasonwyz98 at gmail dot com
New email:
PHP Version: OS:

 

 [2010-04-28 06:33 UTC] jasonwyz98 at gmail dot com
Description:
------------
Hi

When trying to access a non-existing value in a multidimensional array, instead of causing a PHP error, a value was returned.

Jason

Test script:
---------------
$a = array ( 'name' => 'jason' );

echo $a[ 'name' ][ 'none' ];

Expected result:
----------------
PHP Error

Actual result:
--------------
The script returns the string "j".

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-28 06:49 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-04-28 06:49 UTC] rasmus@php.net
Strings can be addressed as arrays of characters which is what you are doing here.  
For strings only numeric array indices are used, so 'none' is cast to an integer, 
which means you are getting index 0, or the first char of the string.  Hence the 
'j'.
 [2010-04-28 22:23 UTC] jasonwyz98 at gmail dot com
Hi Rasmus

You're right, but still this type of auto type conversion isn't very intuitive, especially for non PHP experts coming other languages. This should really be on the change list for future versions of PHP.

Thanks for the help
Jason
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri May 29 21:01:25 2020 UTC