php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65839 $a = 10; $a = $a++; echo $a; //10 But other language like C, will be output: 11
Submitted: 2013-10-05 16:12 UTC Modified: 2013-10-05 16:17 UTC
From: mehedi6060 at gmail dot com Assigned:
Status: Not a bug Package: *Compile Issues
PHP Version: 5.4.20 OS: Windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mehedi6060 at gmail dot com
New email:
PHP Version: OS:

 

 [2013-10-05 16:12 UTC] mehedi6060 at gmail dot com
Description:
------------
$a = 10;
$a = $a++;
echo $a;
what will be output you thinking? output : 11 ?
Sorry, Output is : 10
Because this is a bug on PHP!
But other language(c,c++) this will be : 11
Thanks.
Mehedi Hasan
mehedi6060@gmail.com

Test script:
---------------
$a = 10;
$a = $a++;
echo $a; //10
//But the correct output will be : 11

Expected result:
----------------
$a = 10;
$a = $a++;
echo $a; //10
//But the correct output will be : 11


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-05 16:17 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-10-05 16:17 UTC] nikic@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Please see http://php.net/manual/en/language.operators.precedence.php, which explicitly states that evaluation order is unspecified.

The behavior is also undefined in C++, please see ยง1.9/15 of the C++11 standard.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC