[dev] missuse of negative keys in arrays or PHP bug?
Vilius Šumskas
vilius at lnk.lt
Wed Aug 9 06:14:38 PDT 2006
Hello,
Today I noticed that you I can't create top level forums in Agora. After debugging I found that top level in Agora is represented with constant -1.
It seems that PHP doesn't understand negative keys correctly.
------------------------
Proof of concept 1:
------------------------
$array = array('-1' => 'negative', '1' => 'positive');
echo '1: ' . $array[-1] . '<br>';
echo '2: ' . $array['-1'] . '<br>';
echo '3: ' . $array[1] . '<br>';
echo '4: ' . $array['1'] . '<br>';
------------------------
Result 1:
------------------------
Notice: Undefined offset: -1 in /var/www/html/test.php on line 5
1:
2: negative
3: positive
4: positive
------------------------
Proof of concept 2:
------------------------
$array = array(-1 => 'negative', '1' => 'positive');
echo '1: ' . $array[-1] . '<br>';
echo '2: ' . $array['-1'] . '<br>';
echo '3: ' . $array[1] . '<br>';
echo '4: ' . $array['1'] . '<br>';
------------------------
Result 2:
------------------------
1: negative
Notice: Undefined index: -1 in /var/www/html/test.php on line 6
2:
3: positive
4: positive
Is this PHP bug?
--
Pagarbiai,
Vilius Šumskas
LNK TV sistemų administratorius
mob.: +370 614 75713
http://www.lnk.lt
More information about the dev
mailing list