On Fri, 14 Feb 2020 at 16:33, Nikita Popov <nikita....@gmail.com> 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. Regards, -- Rowan Tommins [IMSoP]