blog

  • Home
  • blog
  • Implementing the Range Operator in PHP

Implementing the Range Operator in PHP

We sometimes come across some amazing posts in other locations, and with the permissions of their authors, repost them on SitePoint. This is one such instance. In the post below, Thomas Punt implements the range operator in PHP. If you’ve ever been interested in PHP internals and adding features to your favorite programming language, now’s the time to learn!

[author_more]

This article assumes that the reader is able to build PHP from source. If this is not the case, then please see the Building PHP chapter of the PHP Internals Book first.

Flying elephpant


This article will demonstrate how to implement a new operator in PHP. The
following steps will be taken to do this:

  • Updating the lexer: This will make it aware of the new operator syntax
    so that it can be turned into a token
  • Updating the parser: This will say where it can be used, as well as what
    precedence and associativity it will have
  • Updating the compilation stage: This is where the abstract syntax tree
    (AST) is traversed and opcodes are emitted from it
  • Updating the Zend VM: This is used to handle the interpretation of the
    new opcode for the operator during script execution

This article therefore seeks to provide a brief overview of a number of PHP’s
internal aspects.

Also, a big thank you to Nikita Popov for
proofreading and helping to improve my article!

Continue reading %Implementing the Range Operator in PHP%

LEAVE A REPLY