Are there any languages that transpile to PHP?

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

    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.

    #1000
    sproingie
    Guest

    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.

    #1001
    NullField
    Guest

    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.

    #1002
    korkof
    Guest

    You have Haxe ([haxe.org](https://haxe.org)) from MotionTwin which can compile in several languages.

    #1003
    skyrim1
    Guest

    Check Swagger which can generate clients from JSON https://editor.swagger.io/

    There is aslo this experiment https://www.peachpie.io/ PHP to IL

    #1004
    LiamHammett
    Guest

    Kind of teetering on the edge of what a transpiler is, there’s Pre (https://preprocess.io/#/) and its underlying parser, yay (https://github.com/marcioAlmada/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.

    #1005
    czbz
    Guest

    Twig [compiles to PHP](https://twig.symfony.com/doc/2.x/internals.html). 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.