php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20366 Switch case inside loop causes no output from script
Submitted: 2002-11-11 13:09 UTC Modified: 2010-12-20 11:44 UTC
From: moptop69 at ntlworld dot com Assigned: jani (profile)
Status: Closed Package: *General Issues
PHP Version: 4.2.3 OS: Win32 (2kSp3) and IIS5
Private report: No CVE-ID: None
 [2002-11-11 13:09 UTC] moptop69 at ntlworld dot com
Whilst converting what was turning out to be an increasingly lengthy and untidy set of IF statements, i found this error.  Similar in effect to http://bugs.php.net/bug.php?id=1812

When a switch case structure is used inside a for loop, the execution of the PHP script is NULL (or sometimes a page header is created)
example1:
  $i=1;

  switch ($i) {
    case 0:
        print "i equals 0";
        break;
    case 1:
        print "i equals 1";
        break;
    case 2:
        print "i equals 2";
        break;
    default:
        print "i is not equal to 0, 1 or 2";
  }

this script works correctly and outputs as you would expect. However, if the switch statement is enclosed in a for loop like so:

  for ($i=0; $i<4; $i++)
  {
    switch ($i) {
      case 0:
        print "i equals 0";
        break;
      case 1:
        print "i equals 1";
        break;
      case 2:
        print "i equals 2";
        break;
      default:
        print "i is not equal to 0, 1 or 2";
    }
  }

the script does not seem to execute at all.

I deliberately introduced bad syntax into the program, leaving off terminating ; and not using $ but the script does not even output errors.  It would appear the the script is not even getting to an error reporting stage.

This has been tested on 4.2.1 and 4.2.3 versions od PHP

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-11 13:12 UTC] derick@php.net
I couldnt not reproduce this, please provide a full script that we can copy & paste to try.

Derick
 [2002-11-11 13:47 UTC] moptop69 at ntlworld dot com
exactly as included previously:

case_test1.php:
---------------
<?

$i=1;

switch ($i) {
    case 0:
        print "i equals 0";
        break;
    case 1:
        print "i equals 1";
        break;
    case 2:
        print "i equals 2";
        break;
    default:
        print "i is not equal to 0, 1 or 2";
}

?>


case_test2.php
--------------
<?

for ($i==0; $i<4; %i++)
{
  switch ($i) {
    case 0:
        print "i equals 0";
        break;
    case 1:
        print "i equals 1";
        break;
    case 2:
        print "i equals 2";
        break;
    default:
        print "i is not equal to 0, 1 or 2";
  }
}

?>

runnning on win2k pro - sp3 - iis5 (all current security patches)
and just in case it makes any difference, I am NOT running any Zend compiler/speed products currently
 [2002-11-11 13:49 UTC] moptop69 at ntlworld dot com
please note, case_test2.php even still has the last deliberate error i introduced to see if it would fail on error
 [2002-11-11 13:49 UTC] derick@php.net
Works perfect here, can you try this snapshot?
http://snaps.php.net/win32/php4-win32-latest.zip

Derick
 [2002-11-11 14:20 UTC] moptop69 at ntlworld dot com
working fine now - under that new release
 [2002-11-11 14:33 UTC] derick@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2010-12-20 11:44 UTC] jani@php.net
-Package: Tidy +Package: *General Issues -Assigned To: +Assigned To: jani
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 17 11:01:28 2024 UTC