Edit report at https://bugs.php.net/bug.php?id=68182&edit=1
ID: 68182
Updated by: [email protected]
Reported by: [email protected]
Summary: array("foo", "bar")() is invalid syntax
-Status: Not a bug
+Status: Open
Type: Bug
Package: PHP Language Specification
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Yeah, the constraints doesn't mention that arrays are allowed. And
> postfix-expression must designate a function... by being a value of type
> string (but not a string literal) that contains the function's name
UVS allows literals http://3v4l.org/V6tTG
Side note: the sentence immediately after
> The number of arguments present in a function call must be at least as many
> as the number of parameters defined for that function.
should clarify that it's the number of *required* parameters.
Then at the end of the Semantics section,
> If postfix-expression is a string, this is a variable function call
which links to 13-functions.md#variable-functions that says
> If a variable name is followed by the function-call operator () (§§), and
> the value of that variable is a string containing the name of a function
> currently defined and visible, that function will be executed.
which also doesn't include arrays.
Previous Comments:
------------------------------------------------------------------------
[2014-10-08 17:24:14] [email protected]
In that case, we should change this is master to reflect it being accepted by PHP7's Uniform Variable Syntax.
------------------------------------------------------------------------
[2014-10-08 14:54:08] cmbecker69 at gmx dot de
> According to the specs, any postfix expression + argument list
> is a valid function call.
No. While it is syntatically valid, there are further constraints:
| postfix-expression must designate a function, either by being
| its name, by being a value of type string (but not a string
| literal) that contains the function's name, or by being a variable
| whose type is Closure (§§) or a derived type thereof.
array("foo", "bar") doesn't fulfill these constraints.
------------------------------------------------------------------------
[2014-10-08 08:06:06] [email protected]
Actually it is valid syntax but you need the uniform variable syntax changes in PHP 7 to get it.
http://3v4l.org/TbcgJ
------------------------------------------------------------------------
[2014-10-08 07:47:11] [email protected]
Description:
------------
According to the specs, https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#function-call-operator any postfix expression + argument list is a valid function call.
Looking at postfix expressions https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#general-3 it says array-creation-expression is a postfix expression.
Test script:
---------------
array("foo", "bar")();
Expected result:
----------------
PHP Fatal error: Class 'foo' not found in Command line code on line 1
Actual result:
--------------
PHP Parse error: syntax error, unexpected '(' in Command line code on line 1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68182&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.