|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48923 while() is not working on PHP5 as it always did
Submitted: 2009-07-14 20:05 UTC Modified: 2009-07-15 12:06 UTC
From: raulsanchezt at gmail dot com Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: 5.2.10 OS: Fedora 6
Private report: No CVE-ID: None
 [2009-07-14 20:05 UTC] raulsanchezt at gmail dot com
What you'll see below are three versions of the same code. Version a) worked for me all along PHP4 (for years and years). After upgrading to PHP5 it's not working anymore. Version b) does not work either. Version c) does work.

Version a) runs indefinitely until I Ctrl-C it.
Version b) runs indefinitely until I Ctrl-C it.
Version c) runs for a millionth of a second and shows the expected result

This code is a great simplification of what I actually coded (a MySQL wrapper). I spent two full weeks trying to find out what was wrong with my new PHP5/MySQL/Zend Debugger/Eclipse implementation until I bumped into this little, unbelievable, never-to-be-expected bug.

Reproduce code:
// version a) while() does not work anymore
$v_x = 0;
$v_success = false;
$_SESSION["v_attempts"] = 20;
while(!$v_success or ($v_x < $_SESSION["v_attempts"]))
  // irrelevant code that may change the value of $v_success

// version b) while() does not work either
$v_x = 0;
$v_success = false;
$_SESSION["v_attempts"] = 20;
while((!$v_success) or ($v_x < $_SESSION["v_attempts"]))
  // irrelevant code that may change the value of $v_success

// version c) this one works
$v_x = 0;
$v_success = false;
$_SESSION["v_attempts"] = 20;
while(($v_success = false) or ($v_x < $_SESSION["v_attempts"]))
  // irrelevant code that may change the value of $v_success

Expected result:
I expect to see the actual value of $v_x, which should be 20.

Actual result:
(gdb) run testfile.php
Starting program: /usr/local/zend/bin/php testfile.php
warning: Lowest section in system-supplied DSO at 0xffffe000 is .hash at ffffe0b4
(no debugging symbols found)
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
[New Thread 4160407232 (LWP 24052)]
Error while reading shared library symbols:
Cannot find new threads: generic error
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
Segmentation fault

NOTE: all three versions produce this output. The three versions run the same as CGIs and as Firefox scripts.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-14 22:42 UTC] ninzya at inbox dot lv
You should be more carefully reading PHP docs and practicing your code debugging rather than posting "cool ass kicking fail code" reports, because your code contains bugs.

1) First two loops are infinite loops because !$v_success is always true (i guess you should put "&&" (and) op instead of "or"), and the last one shows you "expected result" because "$v_success = false" is an assignment operation (nonsense), after which your loop hits false in $v_success and goes on to compare "$v_x < $_SESSION["v_attempts"]" and runs until it's false too.

2) Do you have session_start()'ed at the time of using $_SESSION array?

The segmentation fault you see you get when you hit ctrl-c?

PHP has nothing to do with firefox scripting.
 [2009-07-15 12:06 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Aug 14 03:05:46 2022 UTC