PHP 4.0 Bug #5879: switch() malfunction under very specific conditions

From: Date: Mon, 31 Jul 2000 18:43:29 +0000
Subject: PHP 4.0 Bug #5879: switch() malfunction under very specific conditions
Groups: php.dev 
Request: Send a blank email to php-dev+get-27084@lists.php.net to get a copy of this message
From: dragonzap1@aol.com Operating system: Linux 2.2.16 PHP version: 4.0.1pl2 PHP Bug Type: Scripting Engine problem Bug description: switch() malfunction under very specific conditions Script: <?php $string = 'string'; echo 'There is '; switch($string) { default: echo 'NOT '; break; } echo 'a problem.'; someFunction(NULL); $ec = new EmptyClass(); $somevar = $ec->someMethod(NULL); $ec->someMethod(); $ec->someMethod(); someFunction(); function someFunction($var = '') { } class EmptyClass { function someMethod($data = '') { } } ?> Compile flags: --with-mysql=/usr/local/mysql --with-apache=/usr/local/src/apache --with-gd=/usr/local/src/gd --with-jpeg-dir=/usr/local/src/jpeg --with-xml --with-zlib --enable-versioning Problem: For some reason, this program doesn't always print out "There is NOT a problem." This problem seems to be VERY specific, and doesn't always happen (but if the page is reloaded a bunch of times, it should eventually say 'There is a problem.' and on rare occasions may crash altogether) It will start working as expected, however, if any of the calls to someFunction() or someMethod() are removed, or the arguments are removed or changed to non-NULL values. Adding any other case to the case statement (whether you keep the 'default' or not) will make it function properly as well. The someFunction/EmptyClass/someMethod definitions can be removed while keeping this odd behavior intact, as well as the "$ec = new EmptyClass()", and then adding an "exit;" statement below the "echo 'a problem.';" line but I wanted to try to keep it mostly 'legal' PHP. I know that most people aren't going to do a switch() statement with just a default case (it could happen as a placeholder in the middle of developing something, though, which is how I ran into it), but it may be indicative of a larger problem.

« previous php.dev (#27084) next »