Bug #52650 [Opn->Bgs]: Different result when using a number than a variable.
| From: | aharvey@php.net | Date: | Fri, 20 Aug 2010 05:04:52 +0000 |
| Subject: | Bug #52650 [Opn->Bgs]: Different result when using a number than a variable. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-153627@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52650&edit=1
ID: 52650
Updated by: aharvey@php.net
Reported by: eagler67 at yahoo dot com
Summary: Different result when using a number than a
variable.
-Status: Open
+Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Xp sp3
PHP Version: 5.3.3
Block user comment: N
New Comment:
$index is being set to the result of ($a == $b), which is the boolean
value TRUE, rather than an integer. Incrementing a boolean TRUE results
in it remaining TRUE, so the value of $index never changes. Beyond that,
"TRUE <= 10" (which is what your loop condition effectively boils down
to) will always be true, therefore the loop never ends.
Not a bug, closing.
Previous Comments:
------------------------------------------------------------------------
[2010-08-20 06:54:54] eagler67 at yahoo dot com
Description:
------------
When i put a direct number or variable in a for block, it works fine,
but if i do an equation it fails. Even if it is very simple.
Test script:
---------------
<?php
error_reporting(0);
$index = "0";
$a = "0";
$b = "0";
//As you can see variable returns 1.
echo ">" . ($a==$b) . "<" . "<br>";
// So... this should go from 1 to 10.
// replace "($a==$b)" with 1 and everything works as it should.
for ($index=($a==$b); $index<=10; $index++)
{
// this always prints 1. An endless loop.
echo $index . "<br>";
}
?>
Expected result:
----------------
>1<
1
2
3
4
5
6
7
8
9
10
Actual result:
--------------
>1<
1
1
1
1
1
1
1
1
1
1
1
1
(infinite)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52650&edit=1