js2php

raw JSON →
0.1.7-c verified Fri May 01 auth: no javascript deprecated

A source-to-source transpiler that converts JavaScript (including ES6 features like classes, arrow functions, template strings, and namespaces) into PHP code. Current version 0.1.7-c is marked as experimental and not recommended for production use. It provides a CLI tool for file conversion and supports core JavaScript constructs, Array/JSON/Math/String methods, and Date. Maintained as a hobby project with no recent releases or active development.

error Error: Cannot find module 'javascript-to-php'
cause Package not installed globally or locally.
fix
Run npm install -g javascript-to-php to install globally.
error js2php: command not found
cause Missing global install or PATH issue.
fix
Ensure npm global bin is in PATH or install locally via npx javascript-to-php.
gotcha Package is experimental and should not be used in production.
fix Do not use in production. Consider alternative tools or manual translation.
deprecated No updates since 2016; likely unmaintained.
fix Use a maintained transpiler or avoid reliance on this package.
gotcha ES6 features like Promises, async/await, generators are not supported.
fix Only simple ES6 constructs are supported. Use a more comprehensive transpiler if needed.
npm install javascript-to-php
yarn add javascript-to-php
pnpm add javascript-to-php

Install the CLI tool globally and convert a JavaScript file to PHP, then optionally run the PHP output.

// Install globally
npm install -g javascript-to-php

# Convert a JavaScript file to PHP
js2php examples/simple.js > simple.php

# Or run directly
js2php examples/class.js | php