tolerant-php-parser icon indicating copy to clipboard operation
tolerant-php-parser copied to clipboard

Function names cannot be keywords

Open mattacosta opened this issue 7 years ago • 4 comments
trafficstars

Summary A function name must be a T_STRING token (or whatever its equivalent is in this parser).

Sample code: function empty() {}

Expected Parse error: syntax error, unexpected 'empty' (T_EMPTY), expecting '('

Actual No error.

mattacosta avatar Feb 27 '18 14:02 mattacosta

You may not redeclare language constructs.

jens1o avatar Feb 28 '18 17:02 jens1o

https://3v4l.org/90mgr

It is still a parse error which should be detected. To contrast, function strlen($s) {} would not be a parse error, but evaluation would result in a PHP error at runtime.

Also something to note: empty is a valid name for a class method in PHP 7

TysonAndre avatar Feb 28 '18 19:02 TysonAndre

@jens1o empty is a language construct, not a function

felixfbecker avatar Feb 28 '18 19:02 felixfbecker

Nice catch :)

jens1o avatar Feb 28 '18 19:02 jens1o