question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A call to a global function is parsed the same as one without namespace

See original GitHub issue

Hi! 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:closed
  • Created 7 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
chris-lcommented, Nov 22, 2016

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.

0reactions
chris-lcommented, Nov 25, 2016

… After checking, for die or exit the resulting token is T_EXIT, and the AST is the same (didn’t even realize it)

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 and die, so I googled it to see if that was correct… and surprisingly it was!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found