PHP-to-JavaScript transpiler that converts PHP code into JavaScript code. Version 10.3.0 is the latest stable release, with irregular release cadence. It supports a subset of PHP syntax, including classes, closures, and namespaces, but does not target full PHP compatibility. Key differentiators include the ability to run PHP code in the browser without a server, and integration with the Uniter project. However, it is not actively maintained and has known limitations with newer PHP features.
npm install phptojsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Transpile a simple PHP function to JavaScript.
Replace `const result = phptojs(code)` with `const engine = new PHPToJS(); const result = engine.transpile(code)`.
Replace `.render()` with `.transpile()`.
Use `await engine.transpile(code)` or handle promises.
Replace `<?=` with `<?php echo` in your PHP source.
Use fully qualified namespaces where possible.
Use `const engine = new PHPToJS(); const result = engine.transpile(code);`
Run `npm install php-parser` alongside `phptojs`.
Use `if/elseif` or `switch` statements instead.