|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-05-24 11:18 UTC] 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 ...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 23:00:01 2025 UTC |
Sorry te "Actual result" should be reversed: Warning: Cannot use a scalar value as an array ... array(1) { [10]=> int(1) }