Are there any languages that transpile to PHP?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #999

    I was wondering – are there any languages that transpile to PHP, that can be run through a php interpreter, and make use of other PHP files? For example, JS has Dart, Typescript, Opal, etc, and Erlang has Elixir, and they can be used interchangeably with shared codebases.

    Even though I really appreciate PHP and its significance in web programming, I would love to use something that is slightly less verbose than PHP, but can still be run through a PHP interpreter. I would like to stay within the PHP ecosystem without having to rewrite existing code in a completely different language. My company has hundreds of thousands of lines of PHP code and I would need to make use of it.


    There are several, and you need merely google for “compiles to php” and similar terms. But I’m going to throw some cold water on this: they’re all just research projects and toy hobby projects, developed by individuals who have usually already abandoned them. Using these curiosities means having have zero tooling in your IDE, and error messages will be completely baffling, because there’s no concept of a source map to tell you which line in your original language code is at fault.

    So yes, it’s possible, but not worth it. I recommend exposing your legacy PHP as network services, then writing new code that consumes said services using your preferred different language . You’ll get something actually maintainable and avoid total lock-in to either language.


    Not an answer to the question, but elixir is not transpiled to erlang. Elixir is compiled to an intermediate representation which is then compiled directly to BEAM byte-code.

    It’s more like the Java/Kotlin/Scala/etc ecosystem.


    You have Haxe ([]( from MotionTwin which can compile in several languages.


    Check Swagger which can generate clients from JSON

    There is aslo this experiment PHP to IL


    Kind of teetering on the edge of what a transpiler is, there’s Pre ( and its underlying parser, yay ( which allow you to _preprocess PHP_, meaning you can write one syntax and manipulate it to become real PHP before it’s executed in the PHP runtime.

    Pre handles this process automatically for you and allows to just write `.pre` files with whatever preprocessing extensions you want that it provides, but you could easily write your own to improve any syntax you don’t like in PHP.


    Twig [compiles to PHP]( But you can’t include a PHP file directly in a twig file as far as I know. You can call PHP functions if they are defined on an object that was passed to twig from PHP.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.