Re: ::class wrong case

From: Date: Mon, 25 May 2015 18:02:52 +0000
Subject: Re: ::class wrong case
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-86384@lists.php.net to get a copy of this message
On Mon, 25 May 2015 20:47:32 +0300, Marc Bennewitz <dev@mabe.berlin> wrote:
Hi, I have noted that detecting a class name using "::class" it will return the called case instead of the original case. see http://3v4l.org/97K36 That's annoying as I like to check the right class case on autoload to detect mistakes. Sure, class names in PHP are case-insensitive but filesystems aren't and most autoloader using the FS to find the right file. To catch such kind of mistakes I would like to implement a fast check in my autoloader to get noted on development instead on production. It's currently only possible with ReflectionClass but this will be much slower as with ::class. Are there any reasons to get the called case of the class instead or the original one? Marc
This happens because ::class construction is evaluated at compiled time, without triggering autoloader. That means compiler doesn't know what will be the actual name of a class, it just gives you what you asked for.
It's currently only possible with ReflectionClass but this will be much slower as with ::class.
It's only possible with ReflectionClass if this class was already loaded. There's one way for your autoloader to know if the class name has characters in a wrong case - build a class map and do a check based on this map.

« previous php.internals (#86384) next »