Search code examples
phpphp-extensionphp-internals

Register new T_OPEN_TAG and T_CLOSE_TAG through a C extension?


I'm working on a PHP C extension that needs to register new T_OPEN_TAG <? and T_CLOSE_TAG ?> tags. I don't want to overwrite T_OPEN_TAG and T_CLOSE_TAG, just register new tokens.

Is it possible for a PHP C extension to register new PHP tags? Ex:

<: 1+1 :>

PS: the example above is just an example ;)


Solution

  • No, it's not possible to register new tokens. The only way to do it would be to copy the PHP lexer in its entirety, add your modifications, and then hook your custom lexer into zend_compile_file and zend_compile_string. You don't want to do that.