From: Operating system: Fedora 14 PHP version: 5.3.6 Package: *Programming Data Structures Bug Type: Bug Bug description:Using $variable--; and $variable -= '1'; yield different results.
Description: ------------ While the code below may have other problems, the simple fact of the matter is that when I uncomment "$int--;" and comment "$int -= '1';" the code will loop for at least a minute, but when it is left as is below it does not and will terminate as expected. Since I've been told the two pieces of code have the exact same logic, I have no explaination for this. Please contact me if you know why. The php package was installed using 'yum install php php-mysql' on fedora 14. Test script: --------------- <?php function GeneratePassword($int, $string){ $new_string = ''; while ($int >= 0){ $new_string += $string[rand(0, (strlen($string) - 1))]; //$int--; $int -= '1'; echo 'round'; echo 'dump of int: ' . var_dump($int); echo 'dump of string: ' . var_dump($string); echo 'dump of new_string: ' . var_dump($new_string); } return ($new_string); } fwrite(STDOUT, "Choose an int"); $int = fgets(STDIN); fwrite(STDOUT, "Choose a string"); $string = fgets(STDIN); $pass = GeneratePassword($int, $string); echo 'anything'; echo $pass; ?> Actual result: -------------- CASE 1 USING: //$int--; $int -= '1'; ------------------------------------------------------ php -f delete_me2.php Choose an int2 Choose a stringbb roundint(1) dump of int: string(3) "bb " dump of string: int(0) dump of new_string: roundint(0) dump of int: string(3) "bb " dump of string: int(0) dump of new_string: roundint(-1) dump of int: string(3) "bb " dump of string: int(0) dump of new_string: anything0 CASE 2 USING: $int--; //$int -= '1'; ------------------------------------------------------ php -f delete_me2.php Choose an int2 Choose a stringbb roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " dump of int: string(3) "bb " dump of string: string(0) "" dump of new_string: roundstring(2) "2 " ... (loops for at least 60 seconds) ... -- Edit bug report at http://bugs.php.net/bug.php?id=54549&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54549&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54549&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54549&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54549&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54549&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54549&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54549&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54549&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54549&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54549&r=support Expected behavior: http://bugs.php.net/fix.php?id=54549&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54549&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54549&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54549&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54549&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54549&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54549&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54549&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54549&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54549&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54549&r=mysqlcfg