Req #50354 [Wfx]: Allow trailing commas in function args

From: Date: Sun, 05 Nov 2017 20:04:51 +0000
Subject: Req #50354 [Wfx]: Allow trailing commas in function args
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212471@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=50354&edit=1 ID: 50354 User updated by: jean dot marc dot leger at gmail dot com Reported by: jean dot marc dot leger at gmail dot com Summary: Allow trailing commas in function args Status: Wont fix Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues Operating System: Gnu/Linux i686 PHP Version: 5.2.11 Block user comment: N Private report: N New Comment: @jani any thought on this ? Perhaps you might want to change something to your previous answer. https://wiki.php.net/rfc/trailing-comma-function-calls Previous Comments: ------------------------------------------------------------------------ [2009-12-01 18:57:36] jani@php.net Trailing commas in function args do not exist in any language and will not ever exist in PHP either. ------------------------------------------------------------------------ [2009-12-01 16:25:15] jean dot marc dot leger at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=50354&edit=1

« previous php.bugs (#212471) next »