---- En vie, 26 feb 2021 14:40:03 +0100 Guilliam Xavier 
<guilliam.xav...@gmail.com> escribió ----
 > Hi,
 > 
 > For that example (and most others), you're manipulating file paths anyway,
 > and assume that the FQCN is at least one level deep (i.e. not top-level),
 > so you may as well start with `$p = str_replace('\\', \DIRECTORY_SEPARATOR,
 > $fqcn);` then use `dirname($p)` and/or `basename($p)`.
 > 
 > Now for the (rarer) cases when you actually want the namespace name and/or
 > the unqualified class name, I agree that the current state is not ideal.
 > To my knowledge, you have the choice between "magic" string manipulation
 > (various ways) and "semantic" reflection (e.g. `$r = new
 > \ReflectionClass($fqcn);` -- which may try to autoload the class and throws
 > if it doesn't actually exist -- then use `$r->getNamespaceName()` and/or
 > `$r->getShortName()`).
 > Like `str_contains()` was introduced as a "shorthand" for `false !==
 > strpos()`, something like `get_namespace_name()` and/or `get_short_name()`
 > (or other namings) might be worth considering.
 > 
 > Regards,
 > 
 > -- 
 > Guilliam Xavier
 > 

Hi, Guilliam, 

I think so.

I don't need `dirname` function in order to extract path from a file name. 
However, `dirname` exists in order to simplify a "common" task in a semantic 
way.

Why don't the same  with namespaces ?. There is nothing specific in order to 
work with namespaces only they can be used.

Regards
--
Manuel Canga

Zend Certified PHP Engineer 
Websites: https://manuelcanga.dev | https://trasweb.net
Linkedin: https://es.linkedin.com/in/manuelcanga

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to