Re: [RFC] class_name:namespace

From: Date: Fri, 26 Feb 2021 18:10:34 +0000
Subject: Re: [RFC] class_name:namespace
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-113293@lists.php.net to get a copy of this message


 ---- En vie, 26 feb 2021 14:40:03 +0100 Guilliam Xavier <guilliam.xavier@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


Thread (16 messages)

« previous php.internals (#113293) next »