- This topic has 6 replies, 1 voice, and was last updated 2 months, 3 weeks ago by czbz.
- AuthorPosts
- October 28, 2020 at 5:07 pm #999BlueLensFlaresParticipant
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.
October 28, 2020 at 5:07 pm #1000sproingieGuestThere 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.
October 28, 2020 at 5:07 pm #1001NullFieldGuestNot 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.
October 28, 2020 at 5:07 pm #1002korkofGuestYou have Haxe ([haxe.org](https://haxe.org)) from MotionTwin which can compile in several languages.
October 28, 2020 at 5:07 pm #1003skyrim1GuestCheck Swagger which can generate clients from JSON https://editor.swagger.io/
There is aslo this experiment https://www.peachpie.io/ PHP to IL
October 28, 2020 at 5:07 pm #1004LiamHammettGuestKind 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.
October 28, 2020 at 5:07 pm #1005czbzGuestTwig [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.
- AuthorPosts
- You must be logged in to reply to this topic.