Re: Should PHP reserve a namespace for built-in classes?
| From: | Nick Lockheart | Date: | Sun, 28 Jul 2024 08:48:03 +0000 |
| Subject: | Re: Should PHP reserve a namespace for built-in classes? | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-124663@lists.php.net to get a copy of this message | ||
> On Sun, 2024-07-28 at 00:48 +0200, Claude Pache wrote:
> >
> > For the case of functions (and constants) in the global namespace,
> > there was an RFC on the subject about 4 years ago, which has been
> > declined;
> > see: https://wiki.php.net/rfc/use_global_elements and the
> > discussion threads referenced at the bottom of that page.
>
What about:
namespace foo;
use global functions;
class MyClass{
// do stuff
}
The
use global functions directive goes after the namespace
declaration, but before any other code. It applies to the entire file,
but only to the current file.
It tells the parser that, if a function call is found in the file, use
the global function. Do not make an NS lookup op code, and if the
function is a recognized built-in with a dedicated op code, use the
dedicated op code.
Methods and classes are unaffected.