Convert PHP7 to JavaScript via Babel preset

This project transpiles PHP source code to readable JavaScript source code.
The conversion is implemented as an AST to AST translation (with source maps!). Produced code will have valid JavaScript syntax, but may not work quite the same way due to many conceptual differences between the languages.
| PHP input → | → generated JS |
|---|---|
|
|
You must have Node.js 7 or later. This is a Babel preset. Install it with npm i -S babel-preset-php. Configure it the same way you'd configure other presets such as es2015. For example, set .babelrc to:
``json`
{
"presets": ["php"]
}
and then convert files with Babel as usual, e.g:
`sh`
npm i -g babel-cli
babel file.php -o file.js
Almost all of PHP 7 syntax is supported. Most constructs do vaguely what you'd expect.
* Expressions, control statements, try/catch, functions, closures.
* Classes, with some caveats.
* Private methods and properties aren't private.
* Class constants are not constant.
* Static class properties use ES7 syntax.
* Some common simple functions like strlen, array_pop, and is_bool are translated to JS equivalents. For more complex functions, see Locutus.
* Type hints are translated as Flow annotations.
* PHP's arrays have many features that can't be easily expressed in JS.
* PHP's array() is ambiguous in JS, because it could either be an associative {} or numeric [] array. Empty array is translated as Array(), so you can find and correct it.foreach
* is translated as for-of or for-in loops. They are different in many subtle ways.Foo\Bar
* Mixing of integer and string keys in arrays is going to cause trouble. Forget about preserving order.
* Namespaced names such as are changed to Foo.Bar and it's up to you to make that work.+
* Global-global vs module-"global" scopes are incoherently mixed.
* In JS is ambiguous and type-sensitive, so you'll have lots of 2+2=22 errors. PHP string concatenation . is translated as +.NULL
* Variable-variables work only for globals. Don't use them anyway.
* function-static variables are emulated as globals. Don't use them either.
* PHP's is semantically closer to undefined, and is translated as such.
#### Could be improved. Pull requests welcome!
* Exporting of items as modules.
* Processing of comments.
* Renaming of variable and property names colliding with reserved names, method names, etc.
* Renaming of private methods and properties.
* Re-parsing of assert.
* Concat operator should ensure operands are strings, and + should cast to numbers.+
* Interfaces (could be translated to Flow types).
* Type inference to fix /. and []/{} ambiguities.include_path
* Namespaces.
* Autoloading and . You'll need to manually fix require().__get
* "Magic" methods such as .
#### Not going to happen
* Destructors.
* References. &$a is translated as just a.@
* Copy-on-write arrays. In JS they're passed by reference.
* Internal array pointers.
* Error silencing .
* $_POST[], header(), echo and other request/response dependent code. In Node.js these are not global.die()
* Similarly, process-kiling /exit() are inappropriate in Node.js servers.Error
* There isn't a class hierarchy for exceptions, and JS can't be subclassed correctly.
It works! You may need to add var echo = document.write.bind(document); var global = window;` and patch a few other functions.

This project wouldn't happen without ichiriac's PHP parser and Babel generator.