Edit report at http://bugs.php.net/bug.php?id=53860&edit=1
ID: 53860 Updated by: [email protected] Reported by: soriasoft at gmail dot com Summary: unexpected behaviour in 'foreach' syntax checking -Status: Open +Status: Bogus Type: Bug Package: Unknown/Other Function Operating System: Linux PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: There is no syntax error there though. foreach(...); is a valid loop construct and { expr; } is also a valid construct on its own. Previous Comments: ------------------------------------------------------------------------ [2011-01-27 21:41:41] soriasoft at gmail dot com 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 this bug report at http://bugs.php.net/bug.php?id=53860&edit=1
