Re: [PHP-DEV] Re: [RFC] Deprecate dynamic properties

This is only part of a thread. view whole thread
  116269
October 13, 2021 09:17 guilliam.xavier@gmail.com (Guilliam Xavier)
Off-topic:

if ( class_exists('\\WeakMap') ) {
>
People should stop using a leading slash in FQCN *strings*. \Foo::class is "Foo", not "\Foo". It might work generally but that's asking for problems (e.g. for autoloaders). (Sorry.)
  116270
October 13, 2021 09:21 guilliam.xavier@gmail.com (Guilliam Xavier)
On Wed, Oct 13, 2021 at 11:17 AM Guilliam Xavier xavier@gmail.com>
wrote:

> Off-topic: > > if ( class_exists('\\WeakMap') ) { >> > > People should stop using a leading slash in FQCN *strings*. \Foo::class > is "Foo", not "\Foo". It might work generally but that's asking for > problems (e.g. for autoloaders). > > (Sorry.) >
And of course I mistyped "leading backslash"... Also externals.io seems to strip them, so: \\Foo::class is "Foo", not "\\Foo".
  116271
October 13, 2021 09:52 pierre-php@processus.org (Pierre)
Le 13/10/2021 à 11:17, Guilliam Xavier a écrit :
> Off-topic: > > if ( class_exists('\\WeakMap') ) { > People should stop using a leading slash in FQCN *strings*. \Foo::class is > "Foo", not "\Foo". It might work generally but that's asking for problems > (e.g. for autoloaders). > > (Sorry.) > And why not ? using the FQDN is 100% valid, autoloaders should take care
of this, not the end user. For what it worth, I'm using both, depending upon context, both can make sense. Regards, -- Pierre
  116272
October 13, 2021 12:42 rowan.collins@gmail.com (Rowan Tommins)
On 13/10/2021 10:17, Guilliam Xavier wrote:
> Off-topic: > > if ( class_exists('\\WeakMap') ) { > > > People should stop using a leading slash in FQCN *strings*.  > \Foo::class is "Foo", not "\Foo".  It might work generally but that's > asking for problems (e.g. for autoloaders). > > (Sorry.)
Hah, good point. I should probably just have just used ::class anyway (in which case the leading backslash is the quickest way of the sample code being pasteable into some other file): if ( class_exists(\WeakMap::class) ) { There's probably a bunch of other style no-noes in that example, but I did at least test it worked. :) Regards, -- Rowan Tommins [IMSoP]
  116273
October 13, 2021 13:18 pierre-php@processus.org (Pierre)
Le 13/10/2021 à 14:42, Rowan Tommins a écrit :
> On 13/10/2021 10:17, Guilliam Xavier wrote: >> Off-topic: >> >>     if ( class_exists('\\WeakMap') ) { >> >> >> People should stop using a leading slash in FQCN *strings*. >> \Foo::class is "Foo", not "\Foo".  It might work generally but that's >> asking for problems (e.g. for autoloaders). >> >> (Sorry.) > > > Hah, good point. I should probably just have just used ::class anyway > (in which case the leading backslash is the quickest way of the sample > code being pasteable into some other file): > > if ( class_exists(\WeakMap::class) ) { > > There's probably a bunch of other style no-noes in that example, but I > did at least test it worked. :) > > > Regards, > I am surprised that:
if ( class_exists(\WeakMap::class) ) { Actually works when the class does not exist. It's not really surprising, I mean the FQDN::class in the end only resolve to a simple string no matter that the class exists or not, but, I'm being the devil's advocate here, there are use case were you would want the engine to crash when you explicitly reference/use a non existing class, even when it's only its name. I'm sorry this is off-topic. -- Pierre