Re: Should PHP reserve a namespace for built-in classes?

From: Date: Sat, 27 Jul 2024 22:48:53 +0000
Subject: Re: Should PHP reserve a namespace for built-in classes?
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message


> Le 25 juil. 2024 à 05:22, Nick Lockheart <[email protected]> a écrit :
> 
> 1. Could we have a global setting (maybe php.ini) that makes all built-
> in functions (not built in classes) directly accessible in any
> namespace? That is:
> 
> // php.ini
> AlwaysUseGlobalFunctions = yes
> 
> Then:
> // myclass.php
> namespace foo;
> class Bar{
> 
>   function MyMethod($a,$b){
>      if(array_key_exists($a,$b)){ // no \ before array_key_exists
>         // do something
>      }
>   }
> }
> 
> And with that option set, PHP will know that array_key_exists *is*
> \array_key_exists, even without the slash, and without checking the foo
> namespace for an array_key_exists function first?
> 
> My understanding is that some built-in functions have their own opcode,
> that doesn't get triggered when those built-in functions are called in
> a namespace, unless the built-in is called with a \.
> 
> Having all *functions* default to global would make namespaces a lot
> more user friendly to work with, since we wouldn't have to put
> backslashes in front of everything.
> 
> 

Hi,

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.

—Claude





Thread (10 messages)

« previous php.internals (#124658) next »