Re: Does passing an uninitialized array variable initialize it? (PHP 5)



Or it could have something to with operator precedence:

http://nl3.php.net/manual/en/language.operators.php#language.operators.precedence
In short terms, this is indeed a bug, and it seems they fucked it up:

<?php
$k = 1;
$a = array();
$a[$k] = $k++;
var_dump($a,$k);
?>
array(1) {
[2]=>
int(1)
}
int(2)

'[' _should_ be evaluated BEFORE ++ / -- according to the manual.....

Evaluting should be, according to precedence:

1. $a[$k] = $k++;
2. $a[1] = 1; $k = $k + 1;
3. $a[1] = 1; $k set to 2;
4. $a[1] set to 1, $k set to 2;

Evaluating as it is done:
1. $a[$k] = $k++;
2. $a[$k] = 1; $k = $k + 1;
3. $a[$k] = 1; $k is set to 2;
4. $a[2] is set to 1, $k is set to 2;


(damn, it's hard to write '=' as an 'operator yet to handle' instead of an intermediate 'this is what the vars are now)

If this is really a bug, I'm very curious how they would solve it... It so basic a lot can go wrong in peoples code...
--
Rik Wasmus
.


Quantcast