[SOLVED] php5.0.3: weird bug?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

[SOLVED] php5.0.3: weird bug?

Post by timvw »

Code: Select all

<?php
error_reporting(E_ALL);

$rows = array();
$rows&#1111;] = array('user' => 'timvw', 'credits' => 6);

$newcredits = $rows&#1111;0]&#1111;'credits']++;
echo "newcredits: $newcredits<br>";

$newcredits = $rows&#1111;0]&#1111;'credits'] + 1;
echo "newcredits: $newcredits<br>";

?>
outputs:

newcredits: 6
newcredits: 8

i don't think this behaviour is expected... but i'm always ready to learn something new :)
Last edited by timvw on Sun Mar 06, 2005 9:37 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that's correct.. $var++ is post-increment.. meaning, after execution (returning current state), the variable is incremented. ++$var is pre-increment, as you are expecting.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

[SOLVED]

Post by timvw »

time to go to bed for me... project completed and brain already stopped working :p
Post Reply