Registry / js2php

js2php

JSON →
library0.1.7jsnpmunverified

js2php is an experimental JavaScript to PHP source-to-source transpiler (version 0.1.7). It converts ES6 features like classes, arrow functions, template strings, and many core JavaScript prototypes (Array, JSON, Math, etc.) into PHP. The project is clearly marked as experimental and not recommended for production use. It is published on npm and has an online demo. There is no active development or maintenance; it is effectively abandoned.

npm install js2php
INSTALL
IMPORT
SIG · JS2PHP
J
js2php
javascriptv0.1.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile
import { compile } from 'js2php'
const compile = require('js2php').compile
Package is ESM-only? Actually no, it's CommonJS. But this is a hypothetical import; the package does not export a `compile` function. It is a CLI tool mainly.
default (CLI)
npx js2php input.js > output.php
const js2php = require('js2php')
The package is primarily used as a CLI tool. There is no documented programmatic API.

Shows CLI installation and basic usage: converting a JavaScript arrow function to PHP.

// Install globally npm install -g js2php # Create a simple test file echo 'const add = (a, b) => a + b; console.log(add(1, 2));' > test.js # Transpile and run directly js2php test.js | php
Debug
Known issues
gotchaPackage is experimental and explicitly says 'Please do not use it.'
fix
Do not use in production. Consider alternatives like ReactPHP or writing PHP directly.
affects: >=0.0.0
deprecatedNo updates since 2017? The project is effectively abandoned.
fix
Do not rely on it. There is no active maintenance.
affects: >=0.0.0
gotchaDoes not support full JavaScript; only a subset of ES6 features and core functions.
fix
Test your code thoroughly. Many JavaScript constructs will not transpile.
affects: >=0.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token
js2php does not support all ES6 syntax (e.g., destructuring, spread operator).
fix
Rewrite the code to use supported features only, or use a different transpiler.
ReferenceError: require is not defined
js2php transpiles to PHP and does not emulate Node.js modules.
fix
Do not use require() in the source JavaScript; write code that does not depend on Node.js APIs.
Upgrade
Version history
0.1.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
js2php — npm install js2php · libregistry