php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34601 Different code execution order than in previous PHP versions
Submitted: 2005-09-22 16:50 UTC Modified: 2005-09-22 17:07 UTC
From: steemann at globalpark dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.0RC1 OS: Linux 2.4.21-99
Private report: No CVE-ID: None
 [2005-09-22 16:50 UTC] steemann at globalpark dot de
Description:
------------
I noticed a slight change in the order some instructions   
get executed.   
  
The execution order of instructions for a code like 
$result[$base]=$base++;  
differs from PHP 5.1 to previous versions so that the 
$result variable also has different values as follows:  
   
PHP 4.3.10   : array(1) { [0]=> int(0) }     
PHP 5.0.3    : array(1) { [0]=> int(0) }     
PHP 5.1.0b3  : array(1) { [1]=> int(0) }    
PHP 5.1.0RC1 : array(1) { [1]=> int(0) }    

Reproduce code:
---------------
$base=0;
$result[$base]=$base++;
var_dump($result);


Expected result:
----------------
To keep compatibility with PHP 4.x and 5.0.x:   
   
array(1) { [0]=> int(0) }     

Actual result:
--------------
array(1) { [1]=> int(0) }   
 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-22 17:06 UTC] derick@php.net
Although this is a BC break, you can never rely on this behavior in any computer language where you both *use* a variable and increment it.
 [2005-09-22 17:07 UTC] tony2001@php.net
In this case the behaviour is undefined and if it happen to work for you before, well.. you were lucky.
But it's still undefined (as it is in such languages as C or C++).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 16:01:36 2025 UTC