|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-07-14 22:42 UTC] ninzya at inbox dot lv
[2009-07-15 12:06 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 18 06:00:01 2025 UTC |
Description: ------------ 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 $v_x++; } // 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 $v_x++; } // 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 $v_x++; } 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.