|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2020-10-12 11:14 UTC] xigal18570 at jarilusua dot com
 Description: ------------ Maybe the description is missing here: https://wiki.php.net/rfc/namespaced_names_as_token Test script: --------------- <?php use \Foo\Bar2; // valid use\Foo\Bar3; // valid use \Foo\Bar4 as Bar44; // valid use\Foo\Bar5 as Bar55; // invalid Expected result: ---------------- last variant being valid as well Actual result: -------------- $ sudo docker-compose run --rm --user "$(id --user):$(id --group)" php php test.php Parse error: syntax error, unexpected token "as" in /app/test.php on line 6 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 01:00:01 2025 UTC | 
Notably, if the parse error is removed from the test script, the "use\Foo\Bar3" gives a fatal runtime error of "undefined constant", because that's what PHP has tried to interpret it as. Even defining a class with "namespace use\Foo { class Bar3 {} }" does not lead to valid code, it requires "namespace use\Foo { const Bar3=42; }", which seems incredibly unlikely. Since "runtime" here means "as soon as the file is included", the only downside of the current behaviour is that static analysis can't flag it as definitely invalid; but an opinionated tool could safely warn that it is an almost certain mistake.