Re: [PHP-DEV] Re: Changing the generated name for anon classes

This is only part of a thread. view whole thread
February 13, 2020 10:42 (Nikita Popov)
On Fri, Feb 7, 2020 at 2:35 PM Nikita Popov> wrote:

> On Thu, Feb 6, 2020 at 9:08 PM Andrea Faulds <> wrote: > >> Hi, >> >> Nikita Popov wrote: >> > Hi internals, >> > >> > Based on a suggestion by Nicolas Grekas, >> > changes the generated name for >> > anonymous classes to include the name of the parent class or first >> > interface. So instead of just class@anonymous, you'll see something >> like >> > EventHandler@anonymous in error messages, for example. >> > >> > There's a minor BC break here, for code checking for a "class@anonymous >> " >> > prefix, which should be easy to rectify by checking for "@anonymous" >> > instead. >> > >> > What do people think about doing this change? >> > >> > Regards, >> > Nikita >> > >> >> Perhaps it would make sense to include the namespace used by the code >> which defines/instantiates the class? That might make it easier, when >> looking at a mysterious anonymous class using var_dump() deep in a big >> project perhaps, to find out where it came from. >> > > That would be a possible alternative. This is similar to what we do for > closures. > > As we need the generated name to be reasonably concise, we can only do one > or the other though. I don't know which one is more useful... Maybe Nicolas > wants to chime in. >
I've scrolled through anon class uses in popular composer packages, and that convinced me that parent/interface is probably the most useful information here. Adding the namespace prefix leaves you with something like "Amp\class@anonymous", which doesn't really tell you anything at all, while adding the interface gives you "Amp\CancellationToken@anonymous", which is fairly meaningful. Many more examples like this. Nikita
March 4, 2020 20:19 (Niklas Keller)
Hi Nikita,

while we're changing the naming scheme, could we also get rid of the
NUL byte, please? Binary in logs due to things like get_class really
isn't that nice.

Regarding checking whether something is an anonymous class, how about
adding a function to check whether a class name is an anonymous class?
Something like is_anonymous_class(get_class($obj));