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
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 21:01:29 2024 UTC