Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7876247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:08:19+00:00 2026-06-03T03:08:19+00:00

I have a situation here with post fix and prefix operator.Take a look at

  • 0

I have a situation here with post fix and prefix operator.Take a look at below code snippet. I know some operator precedence exist. but i need a clear explanation regarding this.

<?php
    $a=0;
    echo $a++ + ++$a; //this will result 2 that is ok

    $b=0;
    echo $b++ - ++$b; //this should result 0 isn't it? but am getting -2!
 ?>

Update : The accepted answer describes undefined behavior

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:08:21+00:00Added an answer on June 3, 2026 at 3:08 am

    That always happens if you make use of undefined behaviour. And what you do is undefined behaviour. So don’t try to get an explanation that follows a deterministic logic as undefined is the opposite of that.

    The PHP manual states:

    // mixing ++ and + produces undefined behavior
    $a = 1;
    echo ++$a + $a++; // may print 4 or 5
    

    You extended your question in a comment:

    echo $c=($b++) - (++$b); the result of this statement also getting -2. What you meant by undefined behavior?

    $b = 0 and it shall:
    
    $c=($b++) - (++$b);   | $b is 0  - process first brackets
    $c= 0 - (++$b);       | $b is 1  - process second bracktes inner operator
    $c= 0 - ($b);         | $b is 2  - process second brackets 
    $c= 0 - 2;            | calculate
    $c= -2;
    

    This is obviously how it results for your code when you execute it. It is not defined that this will be always calculated that way, hence undefined. For example if the second bracket is processed first, you’ll get a different result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple situation here. lets face html code first => <form name=geoKey
I don't know if you have run into a similar situation but here's a
Here's the situation. Using a C# program, I have to POST big chunks of
I have a situation here I am preparing a custom post for facebook like
Here's my situation: i have a dialog form that inserts some data on my
I have a strange situation here. In my android app, I have a layout
I have a unique situation over here. I have a button on a form
We have a weird situation going on here. We have setup a local installation
I have a really tough situation in here. There is an array of these
Here's the situation: I have a label's text set, immediately followed by a response.redirect()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.