Re: [RFC] token_get_all() TOKEN_AS_OBJECT mode
| From: | Nikita Popov | Date: | Sat, 15 Feb 2020 15:47:54 +0000 |
| Subject: | Re: [RFC] token_get_all() TOKEN_AS_OBJECT mode | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108600@lists.php.net to get a copy of this message | ||
On Fri, Feb 14, 2020 at 7:30 PM Rowan Tommins <rowan.collins@gmail.com>
wrote:
> On Fri, 14 Feb 2020 at 16:33, Nikita Popov <nikita.ppv@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.
>
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