0

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?

10
  • 1
    Just curious. What is array_map( _ + 1, [1,2,3]) supposed to do? Commented Dec 28, 2013 at 10:01
  • Map function like function($x){return $x+1;} on the array @AmalMurali Commented Dec 28, 2013 at 10:02
  • 1
    @Cthulhu: I see. What does _ mean? Each array element? Commented Dec 28, 2013 at 10:04
  • Not exacly - just missing value. So it kind of turns into function taking a value and returning result for it @AmalMurali Commented Dec 28, 2013 at 10:06
  • 1
    No, this is not possible. You can't do syntax changes from an extension. Commented Dec 30, 2013 at 23:41

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.