TOKEN_AS_OBJECT for token_get_all()
| From: | Nikita Popov | Date: | Thu, 23 Mar 2017 17:16:31 +0000 |
| Subject: | TOKEN_AS_OBJECT for token_get_all() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-98610@lists.php.net to get a copy of this message | ||
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