A call to a global function is parsed the same as one without namespace
See original GitHub issueHi!
If I parse someFunc();
and \someFunc();
, both get parsed exactly as:
["call",
["ns", ["someFunc"]],
[]]
Which means I don’t have any reference that tells me if I’m calling a function from the global namespace or not.
Perhaps \someFunc();
should get parsed as:
["call",
["ns", ["", "someFunc"]],
[]]
(Notice the empty string) What you think about it?
By the way, great parser!
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
swift - Calling a global function which has the same name as a ...
I have a project named Parsing that is a Cocoa Framework. The name of my Xcode target is Parsing. I have a function...
Read more >Essential JavaScript Namespacing Patterns - Addy Osmani
In JavaScript Patterns, Stoyan Stefanov presents a very-clever approach for automatically defining nested namespaces under an existing global ...
Read more >Free Standing Functions in Global Namespace
Put the function in the same namespace as the classes it operates on. This way, it does not clutter the global namespace and...
Read more >Top-level statements - programs without Main methods
Only one top-level file; No other entry points; using directives; Global namespace; Namespaces and type definitions; args; await ...
Read more >Defining namespaces - Manual - PHP
A file containing a namespace must declare the namespace at the top of the file before any other code - with one exception:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well, I think is better if it is mostly an representation of the content, since the behavior could change from one version to another of php. Since php 7 has become stricter, perhaps a future version would not allow the second example of the
use
statement, and would require adding slash to refer to the global namespace? I don’t know, but is not impossible.However, as full disclosure, is also true that is more easy for me that way. I’m creating an unparser for the AST created by php-parser, and that way is easier for me.
But even if is easier for me that way, I do think is better if the AST reflects more the content than the behavior, since, like I said, the behavior could be eventually inconsistent among different php versions.
hehe, actually, I did learned it thanks to php-parser 😉 I was testing php-unparser by parsing code with php-parser and then unparsing it to see if the result was correct, and realized you were generating the same AST for both
exit
anddie
, so I googled it to see if that was correct… and surprisingly it was!