prefix/postfix increment/decrement
The PHP certification guide is short but perfectly clear on the topic of postfix and prefix operations.
My only remark is that due to the font used in this book, the pre/postfix decrement (--) is displayed as one long dash
Also the reader might be wondering if one can combine those operations, like:
< ?php
++$a--;
++$a++;
++($a++);
(++$a)++;
++++$a;
$a----;
?>
Well, these lines are all invalid. And thank God they are! Imagine how hard it would be to read and maintain code that's using such statements.
This entry was posted on Wednesday, March 9th, 2005 and is filed under PHP certification. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

March 10th, 2005 at 3:17 am
I saw something that has never occurred to me, mentioned on SitePoint.
OK, here it goes. What would be the output of the following:

< ?php$i = 10;
$i = $i++;
echo $i;
?>
(Count the smilies to find out)
March 28th, 2005 at 3:17 am
The cert guide mentions something similar, like $i = $i– + 1;
I guess it’s a valid question to expect on the exam, while I would personally advise against using such statements in everyday’s php coding. It would make your code harder to read and you’ll create enemies among your team’s fellow coders
But … you know how “The True Programmer” says: “The code was hard to write, it should be hard to read”