|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-01-27 21:41 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 23:00:02 2025 UTC |
There is no syntax error there though. foreach(...); is a valid loop construct and { expr; } is also a valid construct on its own.