Re: TOKEN_AS_OBJECT for token_get_all()

From: Date: Thu, 23 Mar 2017 22:25:44 +0000
Subject: Re: TOKEN_AS_OBJECT for token_get_all()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-98612@lists.php.net to get a copy of this message
On Thu, 23 Mar 2017 18:16:31 +0100, Nikita Popov <nikita.ppv@gmail.com> wrote:
Hi internals, I'd like to add a new TOKEN_AS_OBJECT flag to token_get_all(), which returns an array of PhpToken objects, rather than the mix of plain strings and arrays we currently have. The PhpToken class is defined as: class PhpToken {
    public $type;
    public $text;
    public $line;
} This has been previously suggested and implemented by Rouven Weßling [1], I've just ported this feature to master and optimized the implementation [2]. Apart from being a nicer interface than the current format, an additional advantage is that the TOKEN_AS_OBJECT mode uses about 1.8x less memory and is 1.4x times faster. Are there any objections to this change? Regards, Nikita [1]: https://github.com/php/php-src/pull/1727 [2]: https://github.com/php/php-src/pull/2430
Regarding memory - would it be possible to return iterator instead of array? Regards, Jan Tvrdik

« previous php.internals (#98612) next »