Extending PHP syntax with extensions?

234 Views Asked by At

I'm trying to introduce few things that I've learned in languages like Scala and Haskell to PHP and experiment with it. To give a concrete example, I would like to extend the PHP syntax to be able to do something like the following:

array_map( _ + 1, [1,2,3]) // returns [2,3,4]

As I understand it "extending the PHP language" means two things:

  • writing an extension in C and putting it as a php.ini extension stanza
  • extending the language (parser) itself (Zend Engine?) which is written in C

I think I want the second item but I see things like xdebug that (to me) pretty much delve deep into PHP internals. I was kinda hoping that perhaps I can extend PHP syntax without the need to wrestle with its parser?

1

There are 1 best solutions below

0
On

To modify PHP's syntax you need to modify its parser. This is not something you can do with an extension. Xdebug might delve deep into the engine, but it only reads information.