TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Babel-preset-php: PHP7 to ES7 syntax translator

130 点作者 farhadhf将近 8 年前

19 条评论

pornel将近 8 年前
That&#x27;s a weekend project and it turned out better than I expected. Thanks to nikic&#x27;s php-parser, astexplorer.net and Babel infrastructure handling the gnarly bits (e.g. source maps just worked).<p>I started it because I hoped it would speed up rewrites of projects from PHP to JS, but now that I&#x27;ve actually seen the results, I realised that bad PHP code makes only worse JS (and there&#x27;s no point rewriting good PHP code).<p>Still, I think it could be useful for sharing some logic between client and the server, without replacing server-side with Node. This isn&#x27;t a VM, so it has zero overhead at the cost of being loose with semantic edge cases.<p>And I find it funny that it now takes 1 line of config to make JS tools work with PHP syntax instead.
评论 #14744434 未加载
评论 #14745740 未加载
评论 #14746565 未加载
STRML将近 8 年前
This is hilarious!<p>We ran across @kornelski yesterday asking about some old babel code (1.) and were wondering what the angle is. Kornel&#x27;s an accomplished coder: he did pngquant and imageoptim.<p>The author himself calls it the &quot;stupidest project I&#x27;ve ever done&quot;. But it&#x27;s probably a nice way to get 90% of the way there when converting PHP fns (such as validation et al) into the browser. Also, and perhaps most importantly, it&#x27;s a great exercise in writing Babel plugins.<p>I really enjoyed this. Thanks for writing it, @kornelski.<p>1. <a href="https:&#x2F;&#x2F;twitter.com&#x2F;kornelski&#x2F;status&#x2F;884485913627295744" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;kornelski&#x2F;status&#x2F;884485913627295744</a>
bluetidepro将近 8 年前
While there already is a bunch of &quot;why&quot; type comments in this thread, it&#x27;s worth noting that in the description of the repo it does say:<p>&gt; &quot;This project is silly and exists only to expand Atwood&#x27;s Law.&quot;<p>So maybe take it with a grain of salt, and just enjoy a neat project for what it is.
mjburgess将近 8 年前
This isnt running PHP in the browser. It&#x27;s running a quasi-JS runtime with PHP syntax.<p>To run &quot;PHP in the browser&quot; you&#x27;d need tests passing on all the major php frameworks, as per, Hack&#x27;s testsuit. Otherwise you&#x27;re forcing people to learn some language not quite either JS or PHP.
评论 #14744441 未加载
beager将近 8 年前
I&#x27;ve generally found the behavior of builtin PHP methods to be less predictable and more involved than in JS, so I wonder if the best approach to writing a transpiler in this case would be to go to the C source and negotiate from there.<p>Having done PHP for years and years before the language itself found adequate elegance, I wouldn&#x27;t want the burden of replicating all its weird behaviors for something like this, at least without seeing the source to understand what&#x27;s happening.
评论 #14744735 未加载
评论 #14744073 未加载
评论 #14744128 未加载
deweller将近 8 年前
One interesting use case for this would be to benchmark functions. How much faster&#x2F;slower do various functions perform in PHP vs. NodeJS?<p>It wouldn&#x27;t be a perfect comparison since the generated JS code might be less optimized. But it could give one a ballpark estimate.
评论 #14744419 未加载
HugoDaniel将近 8 年前
&quot;The conversion is implemented as an AST to AST translation (with source maps!)&quot;<p>Amazing that the code actually reads better than the original. (at least for me)<p>I wonder how many of the php extensions can be easily ported to JS code as well ?
kodablah将近 8 年前
Heh, I did it the other direction back in the day as a toy [0]. Back in TypeScript&#x27;s earlier days I figured it could be a neat frontend for the otherwise ugly PHP...not really.<p>0 - <a href="http:&#x2F;&#x2F;cretz.github.io&#x2F;pratphall&#x2F;" rel="nofollow">http:&#x2F;&#x2F;cretz.github.io&#x2F;pratphall&#x2F;</a> - <a href="https:&#x2F;&#x2F;github.com&#x2F;cretz&#x2F;pratphall" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cretz&#x2F;pratphall</a>
awkward将近 8 年前
This is a good scary story for anyone who complains too much about the complexity of modern javascript.
megamindbrian将近 8 年前
Why not just compile phplib using <a href="https:&#x2F;&#x2F;github.com&#x2F;kripken&#x2F;emscripten" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kripken&#x2F;emscripten</a> and call the library functions directly?
评论 #14751081 未加载
csomar将近 8 年前
I could see many ways how this can go wrong and be popular with guys who have PHP code and want to run it on the browser because they 1. either don&#x27;t master javascript or 2. want to save time.
agumonkey将近 8 年前
I wonder how easy it is to translate between dynamic languages since they all support a quite similar core set (classes, closures, sets, dicts, iterables ...)
评论 #14745557 未加载
arcosdev将近 8 年前
But...but...why?
评论 #14744055 未加载
评论 #14744056 未加载
评论 #14744014 未加载
aussieguy1234将近 8 年前
Gitlab is down
alansmitheebk将近 8 年前
Why?
cwyers将近 8 年前
Ah, now we can run HN&#x27;s least favorite language on top of HN&#x27;s second least favorite language.
评论 #14745470 未加载
_pmf_将近 8 年前
Why not? JSX paved the way for the successful return to PHP3 style development.
评论 #14744319 未加载
lolive将近 8 年前
So sick! &#x2F;o\
jorgec将近 8 年前
Fine but its dangerous. Javascript&#x2F;Ecmascript, is a poor designed language, the scope of the variables is broken. Instead, PHP is well defined in this aspect.
评论 #14744035 未加载
评论 #14743947 未加载
评论 #14744276 未加载