#28503 [Ana->Ver]: Operator $x[$y] behavior is incorrect
| From: | sniper@php.net | Date: | Sun, 06 Mar 2005 19:07:01 +0000 |
| Subject: | #28503 [Ana->Ver]: Operator $x[$y] behavior is incorrect | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-74946@lists.php.net to get a copy of this message | ||
ID: 28503
Updated by: sniper@php.net
Reported By: tomas dot matousek at matfyz dot cz
-Status: Analyzed
+Status: Verified
Bug Type: Scripting Engine problem
-Operating System: WinXP
+Operating System: *
-PHP Version: 5.0.0RC2
+PHP Version: 4CVS, 5CVS (2005-03-06)
Previous Comments:
------------------------------------------------------------------------
[2004-05-24 19:34:43] pollita@php.net
I agree it's inconsistent, as it happens though it's being discussed
already because of a related (but not identical) bug report:
http://bugs.php.net/28476
------------------------------------------------------------------------
[2004-05-24 11:21:26] tomas dot matousek at matfyz dot cz
Sorry te "Actual result" should be reversed:
Warning: Cannot use a scalar value as an array ...
array(1) {
[10]=>
int(1)
}
------------------------------------------------------------------------
[2004-05-24 11:18:46] tomas dot matousek at matfyz dot cz
Description:
------------
Why does operator [] create a new array when applied on boolean FALSE
and doesn't do so when applied on integer 0? One of that is IMHO
wrong. Either this operator should create a new array on everything
that is empty() or it should fail on all scalar types and make a new
array only from empty string "" or NULL or uninitialized variable.
Reproduce code:
---------------
$a = 0;
$a[10] = 1;
var_dump($a);
$b = false;
$b[10] = 1;
var_dump($b);
Expected result:
----------------
Warning: Cannot use a scalar value as an array ...
Warning: Cannot use a scalar value as an array ...
Actual result:
--------------
array(1) {
[10]=>
int(1)
}
Warning: Cannot use a scalar value as an array ...
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28503&edit=1