Re: Re: [RFC] Deprecate dynamic properties
| From: | Pierre | Date: | Wed, 13 Oct 2021 13:18:45 +0000 |
| Subject: | Re: Re: [RFC] Deprecate dynamic properties | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116273@lists.php.net to get a copy of this message | ||
Le 13/10/2021 à 14:42, Rowan Tommins a écrit :
On 13/10/2021 10:17, Guilliam Xavier wrote: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. -- PierreOff-topic: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') ) {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.)