Bug #51677 [Com]: Multidimensional array returns non-existing value
| From: | jasonwyz98 at gmail dot com | Date: | Wed, 28 Apr 2010 20:23:29 +0000 |
| Subject: | Bug #51677 [Com]: Multidimensional array returns non-existing value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-150011@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51677&edit=1
ID: 51677
Comment by: jasonwyz98 at gmail dot com
Reported by: jasonwyz98 at gmail dot com
Summary: Multidimensional array returns non-existing value
Status: Bogus
Type: Bug
Package: Arrays related
Operating System: Ubuntu 9.10
PHP Version: 5.3.2
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2010-04-28 06:49:08] 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 06:33:55] 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".
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51677&edit=1