Bug #53860 [NEW]: unexpected behaviour in 'foreach' syntax checking

From: Date: Thu, 27 Jan 2011 20:41:42 +0000
Subject: Bug #53860 [NEW]: unexpected behaviour in 'foreach' syntax checking
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-158248@lists.php.net to get a copy of this message
From: Operating system: Linux PHP version: 5.3.5 Package: Unknown/Other Function Bug Type: Bug Bug description:unexpected behaviour in 'foreach' syntax checking Description: ------------ I found and unexpected behavior in the syntax checking. When you write a ';' after the open brace, the parser doesn't display an error or notice message, and executes the code with the last element of the array. I test this in php5.3 and php5.2. This "innocent" ; is realy hard to debug. The enviroments: joac@pepino ~/ReposGcoop $ php -v PHP 5.3.3 with Suhosin-Patch (cli) (built: Jul 25 2010 12:50:19) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies debdev@jaula:~/www$ php -v PHP 5.2.6-1+lenny9 with Suhosin-Patch 0.9.6.2 (cli) (built: Aug 4 2010 03:25:57) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Xdebug v2.0.3, Copyright (c) 2002-2007, by Derick Rethans Test script: --------------- <?php function show_array(&$data_array){ foreach ($data_array as $key=>$value); { print "$key => $value\n"; if ( is_array( $value ) ){ show_array1( $value ); print "End of nested Array\n"; } } }; $evil_array = array ( 'item1' => array ( 'item1_1' => array( 'item1_1_1' => 1, 'item1_1_2' => 2 ), 'item1_2' => array( 'item1_2_1' => 3,), ), 'item2' => '4'); show_array($evil_array); ?> Output: joac@pepino ~/ReposGcoop $ php bugphp.php item2 => 4 Expected result: ---------------- I expect some error or notice for this syntax error. Actual result: -------------- joac@pepino ~/ReposGcoop $ php bugphp.php item2 => 4 -- Edit bug report at http://bugs.php.net/bug.php?id=53860&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53860&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53860&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53860&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53860&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53860&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53860&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53860&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53860&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53860&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53860&r=support Expected behavior: http://bugs.php.net/fix.php?id=53860&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53860&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53860&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53860&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53860&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53860&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53860&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53860&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53860&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53860&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53860&r=mysqlcfg

« previous php.bugs (#158248) next »