Re: [PHP-DEV] [RFC] token_get_all() TOKEN_AS_OBJECT mode

This is only part of a thread. view whole thread
February 15, 2020 15:47 (Nikita Popov)
On Fri, Feb 14, 2020 at 7:30 PM Rowan Tommins>

> On Fri, 14 Feb 2020 at 16:33, Nikita Popov> wrote: > > > This constructor will initialize the corresponding properties. Now, the > > behavior that would make most sense to me (if extension of the class is > > allowed) is that MyPhpToken::getAll() is going to create the new tokens > > based on "new MyPhpToken($id, $text, $line, $pos)". If we mark the > > constructor final, then we could hardcode the construction behavior of > the > > base class without introducing any kind of weird rules, it would be just > > the usual language semantics. > > > > > It's worth noting that this is how ext/simplexml works: the $class > parameter of simplexml_load_string and simplexml_load_file must be the name > of a class that inherits from SimpleXMLElement, and an instance of that > class will be constructed for each element of the document. The constructor > of SimpleXMLElement is final, so the internal initialisation logic doesn't > have to actually call it, it can just initialise the private state > directly. >
Thanks for pointing that out, I wasn't aware that SimpleXMLElement is already using this pattern. Given that, I've updated the RFC to go with that option now. Nikita