php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52650 Different result when using a number than a variable.
Submitted: 2010-08-20 06:54 UTC Modified: 2010-08-20 07:04 UTC
From: eagler67 at yahoo dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.3 OS: Xp sp3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: eagler67 at yahoo dot com
New email:
PHP Version: OS:

 

 [2010-08-20 06:54 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-20 07:04 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-08-20 07:04 UTC] aharvey@php.net
$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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 06:01:32 2025 UTC