Re: [RFC] class_name:namespace
>
> Hi,
>
> Note that (typos aside) this example cannot work as-is, because static::namespace
> (like static::class) cannot be resolved at compile-time, and therefore cannot be
> assigned to a constant.
>
> More generally, in the various examples you provided, the namespace is not resolved at
> compile-time: it is either static::namespace or $fullClassName::namespace where $fullClassName is
> provided by the autoloader. As such, instead of a ::namespace magic class constant, it might be more
> appropriate to have a helper function, say get_namespace(), which has the additional
> benefit to work not only on (fully qualified) class names, but also on function, constant and
> namespace names (in the case of namespace names, it would return the name of the parent namespace).
>
> —Claude
>
>
Hi, Claude,
That's sound great. Something like dirname[1] but with namespaces.
But...in that case, I also add a new function like basename but with namespaces. Example autoload
for WordPress :
```
function autoload( $ful_class_name ) {
$class_ path = str_replace('\\', '/', get_namespace( $ful_class_name ) );
$class_name = strtolower( get_base_namespace( $ful_class_name ) );
require "{$class_path}/class-{$class_name}.php";
}```
[1]: https://www.php.net/manual/es/function.dirname.php
[2]: https://www.php.net/manual/es/function.basename.php
Regards
--
Manuel Canga
Zend Certified PHP Engineer
Websites: https://manuelcanga.dev | https://trasweb.net
Linkedin: https://es.linkedin.com/in/manuelcanga
Thread (16 messages)