forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow trailing commas in function and method calls
- Loading branch information
Showing
6 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
Zend/tests/function_arguments/call_with_leading_comma_error.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--TEST-- | ||
Leading commas in function calls is not allowed | ||
--FILE-- | ||
<?php | ||
foo(,$foo); | ||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected ',' in %s on line %d |
8 changes: 8 additions & 0 deletions
8
Zend/tests/function_arguments/call_with_multi_inner_comma_error.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--TEST-- | ||
Multiple inner commas in function calls is not allowed | ||
--FILE-- | ||
<?php | ||
foo($foo,,$bar); | ||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected ',', expecting ')' in %s on line %d |
8 changes: 8 additions & 0 deletions
8
Zend/tests/function_arguments/call_with_multi_trailing_comma_error.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--TEST-- | ||
Multiple trailing commas in function calls is not allowed | ||
--FILE-- | ||
<?php | ||
foo($foo,,); | ||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected ',', expecting ')' in %s on line %d |
8 changes: 8 additions & 0 deletions
8
Zend/tests/function_arguments/call_with_only_comma_error.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--TEST-- | ||
Single comma in function calls is not allowed | ||
--FILE-- | ||
<?php | ||
foo(,); | ||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected ',' in %s on line %d |
97 changes: 97 additions & 0 deletions
97
Zend/tests/function_arguments/call_with_trailing_comma_basic.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--TEST-- | ||
Allow trailing commas in function and method calls | ||
--FILE-- | ||
<?php | ||
function foo(...$args) { | ||
echo __FUNCTION__ . "\n"; | ||
var_dump($args); | ||
} | ||
foo( | ||
'function', | ||
'bar', | ||
); | ||
|
||
class Foo | ||
{ | ||
public function __construct(...$args) { | ||
echo __FUNCTION__ . "\n"; | ||
var_dump($args); | ||
} | ||
|
||
public function bar(...$args) { | ||
echo __FUNCTION__ . "\n"; | ||
var_dump($args); | ||
} | ||
|
||
public function __invoke(...$args) { | ||
echo __FUNCTION__ . "\n"; | ||
var_dump($args); | ||
} | ||
} | ||
|
||
$foo = new Foo( | ||
'constructor', | ||
'bar', | ||
); | ||
|
||
$foo->bar( | ||
'method', | ||
'bar', | ||
); | ||
|
||
$foo( | ||
'invoke', | ||
'bar', | ||
); | ||
|
||
$bar = function(...$args) { | ||
echo __FUNCTION__ . "\n"; | ||
var_dump($args); | ||
}; | ||
|
||
$bar( | ||
'closure', | ||
'bar', | ||
); | ||
|
||
# Make sure to hit the "not really a function" language constructs | ||
unset($foo, $bar,); | ||
var_dump(isset($foo, $bar,)); | ||
?> | ||
--EXPECT-- | ||
foo | ||
array(2) { | ||
[0]=> | ||
string(8) "function" | ||
[1]=> | ||
string(3) "bar" | ||
} | ||
__construct | ||
array(2) { | ||
[0]=> | ||
string(11) "constructor" | ||
[1]=> | ||
string(3) "bar" | ||
} | ||
bar | ||
array(2) { | ||
[0]=> | ||
string(6) "method" | ||
[1]=> | ||
string(3) "bar" | ||
} | ||
__invoke | ||
array(2) { | ||
[0]=> | ||
string(6) "invoke" | ||
[1]=> | ||
string(3) "bar" | ||
} | ||
{closure} | ||
array(2) { | ||
[0]=> | ||
string(7) "closure" | ||
[1]=> | ||
string(3) "bar" | ||
} | ||
bool(false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters