$x=1;
echo $x + $x++ + $x++ + $x;
abhi10kumar 0 Junior Poster
Recommended Answers
Jump to PostAnswer is 8 not 6
Jump to PostThis is the code syntax tree from http://phpfiddle.org/
array( 0: Expr_Assign( var: Expr_Variable( name: x ) expr: Scalar_LNumber( value: 1 ) ) 1: Stmt_Echo( exprs: array( 0: Expr_Plus( left: Expr_Plus( left: Expr_Plus( left: Expr_Variable( name: x ) right: Expr_PostInc( var: Expr_Variable( name: x ) …
Jump to PostI can get 4 different answers every time, heh heh!
Jump to Postaccording to the manual: operators precedence
it has an 'Undefined order of evaluation'
and may 'change between versions of PHP or depending on the surrounding code'
All 13 Replies
Aeonix 71 Posting Whiz
tNicknames 15 Newbie Poster
diafol commented: Aha! +15

diafol
Aeonix 71 Posting Whiz

diafol
Aeonix commented: Neat tool. +1
tNicknames 15 Newbie Poster

diafol
Aeonix 71 Posting Whiz

diafol
tNicknames 15 Newbie Poster
pzuurveen 90 Posting Whiz in Training
diafol commented: Good link. Thought I was going insane. Well maybe I am, but not 'coz of this! +15

diafol
JerrimePatient 5 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.