php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31512 wrong expression execution order
Submitted: 2005-01-12 11:57 UTC Modified: 2005-01-12 13:29 UTC
From: dan at yes dot lt Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.3.10 OS: any
Private report: No CVE-ID: None
 [2005-01-12 11:57 UTC] dan at yes dot lt
Description:
------------
Arithmetic expression execution returns unexpected results with ++ or -- operators.

Reproduce code:
---------------
$a = 10;   
$c = $a++ + ++$a;
echo "$c\n";

$a = 10;
$c = ++$a + $a++;
echo "$c\n";

Expected result:
----------------
22
22

Actual result:
--------------
22
23 <- ?? Why ??

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-12 13:01 UTC] tony2001@php.net
Submitted twice.
 [2005-01-12 13:19 UTC] dan at yes dot lt
<?php

$a = 10;  

$b = &$a;

$a = 10;  
$c = $a++ + ++$a;
echo "$c\n\n"; // 22

$a = 10;
$c = ++$a + $a++;
echo "$c\n\n"; // 23 ??

?>

it works if there is no $b =&$a reference, and fails, if there is that
reference...
 [2005-01-12 13:29 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 14:01:32 2024 UTC