php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35709 array key assignation
Submitted: 2005-12-16 15:15 UTC Modified: 2005-12-16 15:26 UTC
From: ait-ali dot mohamed at laposte dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.1.1 OS: WIN 2K
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
1 + 44 = ?
Subscribe to this entry?

 
 [2005-12-16 15:15 UTC] ait-ali dot mohamed at laposte dot net
Description:
------------
It seems to be an bas assignation for the array.
The engine begins to increment the variable, before
assign in the array's key.

Reproduce code:
---------------
<?
$table = array();
$i = 0;
$table [$i][0] = $i++;
print_r($table);
?>



Expected result:
----------------
Array
(
    [0] => Array
        (
            [0] => 0
        )

)

Actual result:
--------------
Array
(
    [1] => Array
        (
            [0] => 0
        )

)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-16 15:21 UTC] tony2001@php.net
The behaviour of such code is undefined in all languages I know of and may vary depending on the optimization level used.
 [2005-12-16 15:26 UTC] ait-ali dot mohamed at laposte dot net
But this code works in previous versions (5.0.0, 4.3.9, 4.3.8), without change anything in optimization.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC