You are here: Re: Does passing an uninitialized array variable initialize it? (PHP 5) « PHP Programming Language « IT news, forums, messages
Re: Does passing an uninitialized array variable initialize it? (PHP 5)

Posted by Rik on 07/30/07 21:51

Or it could have something to with operator precedence:

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

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

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

Evaluting should be, according to precedence:

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

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


(damn, it's hard to write '=3D' as an 'operator yet to handle' instead o=
f 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация