From:             jean dot marc dot leger at gmail dot com
Operating system: Gnu/Linux i686
PHP version:      5.2.11
PHP Bug Type:     Scripting Engine problem
Bug description:  Syntax inconsistency in function (call & definition) arguments

Description:
------------
PHP has always tolerated one trailing comma (,) at the end of array
declaration, producing no error. I assume this is intended to easily
generate array-syntax compliant php code in a loop.
<?php
/* Array context */
$a = array();          // works fine
// $a = array(,);      // will not work: Parse error: syntax error,
unexpected ',', expecting ')'
$a = array(1,2);       // works fine
$a = array(1,2,);      // works fine : PHP syntax tolerance : last comma
is ignored
//$a = array(1,2,3,,); // will not work: Parse error: syntax error,
unexpected ',', expecting ')'
?>

It would be great to have PHP behaving the same way in function
declaration and function call parameters contexts.

Reproduce code:
---------------
<?php
/* function declaration context */
function myfunction ()     {return true;}    // works
//function myfunction1 (,){return true;}     // will not work: Parse
error: syntax error, unexpected ')', expecting '&' or T_VARIABLE
function myfunction2($a,$b){return true;}    // works
//function myfunction3($a,$b,){return true;} // will not work (should
have): Parse error: syntax error, unexpected ')', expecting '&' or
T_VARIABLE

/* function call context */
myfunction();           // works fine
//myfunction2(,);       // will not work: throws Parse error: syntax
error, unexpected ',', expecting ')'
myfunction3($a,$a);     // works fine
//myfunction4($a,$a,);  // will not work (should have): throws Parse
error: syntax error, unexpected ')'

Expected result:
----------------
<?php
// This declaration shouldn't raise any parse error
function myfunction3($a,$b,){return true;}
// neither does this function call :
myfunction4(1,2,);
// in either cases, the last comma should just be silently ignored by the
parser.

Actual result:
--------------
<?php
function myfunction3($a,$b,){return true;} 
// Parse error: syntax error, unexpected ')', expecting '&' or T_VARIABLE

myfunction4($a,$a,);  
// Parse error: syntax error, unexpected ')'


-- 
Edit bug report at http://bugs.php.net/?id=50354&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50354&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50354&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50354&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50354&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50354&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50354&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50354&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50354&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50354&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50354&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50354&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50354&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50354&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50354&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50354&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50354&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50354&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50354&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50354&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50354&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50354&r=mysqlcfg

Reply via email to