Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to develop a functional language based on PHP opcode?

Similar to Scala/bytecode or F#/CIL

Has somebody done this already?

share|improve this question
Is the bytecode even well-defined, stable and intended for other projects to target? – delnan Nov 23 '11 at 13:34
up vote 8 down vote accepted

As PHP opcodes and the functional languages you listed are Turing Complete the answer is trivially, yes, it is possible. It may be more interesting though to ask if anyone has done this already.

After a bit of search on google and a few online code repositories there do seem to be people dabling in functional PHP however I don't see anything approaching a new language implemented in opcodes.

share|improve this answer

As @jk. writes, since PHP opcode is Turing Complete it's definitely possible. But you should keep in mind that the Zend Engine is developed and optimized with only PHP in mind and it's not supposed to be a virtual machine that supports other languages. AFAIK no one has proposed building a new language for the Zend Engine, functional or not.

What you may find interesting though is the Parrot VM, which supports PHP (via Pipp) and a long list of other languages, including the nearly pure esoteric functional language Unlambda and Arc, a dialect of Lisp. On Parrot's functional support, Wikipedia tell us:

Parrot has rich support for several features of functional programming including closures and continuations, both of which can be particularly difficult to implement correctly and portably, especially in conjunction with exception handling and threading. Implementing solutions to these problems at the virtual machine level prevents repeated efforts to solve these problems in the individual client languages.

PHP does provide some functional concepts, like anonymous functions, but I don't think it would be practical to consider building a functional language on top of the Zend Engine.

share|improve this answer
this is actually more what my question was directed at - if the Zend Engine is suitable for other languages than PHP – Raffael Nov 23 '11 at 14:13
@Raffael1984 Yeap, I got that, that's why I expanded jk.'s answer and provided Parrot as an example where PHP and functional languages co-exist. The Zend Engine is somewhere in the space between an interpreter and a Virtual Machine. It provides no facilities for any other languages or anything that would help you build such facilities. In theory, since it's open source, you can build anything for it, but that's simply not practical. You can read more on its architecture here: – Yannis Nov 23 '11 at 14:18
The core question I am wondering about is weather you can think of opcode as something like cli or bytecode and if there is potential towards a development onto such level.… – Raffael Nov 23 '11 at 14:47
@Raffael1984 JVM and CLI were designed with the intent to support multiple languages, Zend Engine was not. Currently there isn't a simple way to use the Zend Engine to interpret opcode, it's tightly coupled with PHP. It's possible but not currently supported and there's no indication that there's any intent for the Zend Engine to support multiple languages in the future. But you should really ask Zend for more details. – Yannis Nov 23 '11 at 15:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.