Edit report at http://bugs.php.net/bug.php?id=54549&edit=1
ID: 54549
Comment by: hotmail22a23 at hotmail dot com
Reported by: account22a23 at hotmail dot com
Summary: Using $variable--; and $variable -= '1'; yield
different results.
Status: Open
Type: Bug
Package: *Programming Data Structures
Operating System: Fedora 14
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
Code was run from command line.
Previous Comments:
------------------------------------------------------------------------
[2011-04-17 14:03:37] account22a23 at hotmail dot com
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 this bug report at http://bugs.php.net/bug.php?id=54549&edit=1