PHPackages                             aftermarketpl/php2js - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aftermarketpl/php2js

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aftermarketpl/php2js
====================

Quick and dirty PHP to JavaScript converter.

v0.1.1(7y ago)120[2 issues](https://github.com/aftermarketpl/aftermarketpl-php2js/issues)Apache-2.0PHPPHP &gt;=7.1

Since Apr 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/aftermarketpl/aftermarketpl-php2js)[ Packagist](https://packagist.org/packages/aftermarketpl/php2js)[ RSS](/packages/aftermarketpl-php2js/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (4)Versions (10)Used By (0)

aftermarketpl-php2js
====================

[](#aftermarketpl-php2js)

This project aims to create a fairly complete PHP to JavaScript transpiler.

Its primary purpose is to aid internal development of [AfterMarket.pl](https://www.aftermarket.pl/), but since it may also be of an interest to the general public, it is released under Apache license and available as a composer package.

Project aims
------------

[](#project-aims)

The most important design goals of the converter are as follows:

- It is intended for development of new code, rather than converting existing code. It will **not** magically convert all your existing legacy PHP code to JavaScript, because it would require effort that is well beyond the scope of the project. But if you write your PHP code bearing in mind the transpiler's limitations, it should be robust enough for most of your needs.
- The resulting JavaScript code is meant to be run in a browser, not in a server environment. This means that it does not use any fancy Node.js modules or features, which also further limits the range of accepted PHP constructs and features.
- The resulting JavaScript code should be human-readable and easily correspond to the input PHP code, so that it can be easily inspected and debugged by humans.

Limitations
-----------

[](#limitations)

Since it is not a general purpose transpiler, there are limits on what the transpiler accepts. If it encounters PHP code which it cannot transpile properly, it will normally throw an exception, although in some edge cases it can produce JavaScript code from PHP code it should theoretically not support; such code is not guaranteed to run properly.

At this point the transpiler will convert most of **functional** PHP code, which does not contain any class definitions or usage. Thus, the following sample PHP code will translate nicely to JavaScript:

```
function myFunc($param)
{
    return $param + 1;
}
$d = $a ? $b + myFunc($c) : $b ** $c;
```

The resulting JavaScript is:

```
var b, c, d, a;
function myFunc(param)
{
    return param + 1;
}
d = a ? b + myFunc(c) : Math.pow(b, c);
```

The produced code is easily readable by humans, and contains only minimum overhead.

### PHP syntax not yet accepted:

[](#php-syntax-not-yet-accepted)

The following PHP constructs are not supported at the moment, and will likely not be supported at all, although we may implement some of them if time permits:

**Computed variable and function names**

Seriously, you really shouldn't be doing this anyway.

```
$a = $$b;
$a = $b(); // May be supported in the future
```

**String subscripting with brackets**

This mainly stems from the fact that the transpiler does not know whether the variable is an array or a string. With PHP 7 type hinting, this may be improved in the future if the type of the variable can be deduced.

```
$a = "string";
$b = $a[1]; // Use substr() instead
```

**Some array operations**

Again, with the plus operator the transpiler does not know if the variable is a numeric or an array. PHP 7 type hinting may improve this as well.

```
$array = array();
$a = $array + $array2;
```

**Some binary and assigmment operators**

Some of these operators may be supported with ugly JavaScript, so the situation may improve.

```
$a = $b  $c; // May be supported in the future
$a = $b xor $c;
$a = $b ?: $c; // May be supported in the future
$a ??= $b;
$a **= $c;
```

**Variable references**

They cannot be easily reproduced in JavaScript in general.

```
$a = &$b;
function func(&$a) {}
```

**Multi-level break and continue**

They cannot be easily reproduced in JavaScript in general.

```
continue 2;
break $a;
```

### Classes and exceptions:

[](#classes-and-exceptions)

They are at the moment not supported at all, but we intend to work on them so you can expect a fairly broad support in the future.

PHP standard library
--------------------

[](#php-standard-library)

PHP is not just a language; it is also a quite extensive library of standard functions such as `substr()` or `preg_match()`. We intend to implement a broad range of these functions, but since it requires a significant effort, it will take us some time to get there. Some functions will never be supported because they make no sense in a browser environment (such as file I/O). Some functions require too much effort compared to expected gain, so we may choose not to implement them (although you can do it, and we will gladly incpororate your code!). In general, we want to focus on string and array functions first because that's what we use in our own code.

As a teaser, a few string functions are implemented already, so you can try code such as this:

```
$a = strlen($b);
$a = substr($b, $c, 1);
$a = strtolower($b);
```

The resulting JavaScript will be:

```
a = (b).length;
a = (b).charAt(c);
a = (b).toLowerCase();
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

9

Last Release

2568d ago

PHP version history (2 changes)v0.0.1PHP &gt;=5.6

v0.1.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d595c9ce500a72508c53016d31214801b3e28cb0a261494cf629db12f457c5e5?d=identicon)[aftermarketpl](/maintainers/aftermarketpl)

---

Top Contributors

[![MichalPleban](https://avatars.githubusercontent.com/u/9946531?v=4)](https://github.com/MichalPleban "MichalPleban (32 commits)")[![psos](https://avatars.githubusercontent.com/u/30193550?v=4)](https://github.com/psos "psos (1 commits)")

---

Tags

javascript

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aftermarketpl-php2js/health.svg)

```
[![Health](https://phpackages.com/badges/aftermarketpl-php2js/health.svg)](https://phpackages.com/packages/aftermarketpl-php2js)
```

###  Alternatives

[tightenco/ziggy

Use your Laravel named routes in JavaScript.

4.3k41.6M267](/packages/tightenco-ziggy)[matthiasmullie/minify

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

2.0k30.5M336](/packages/matthiasmullie-minify)[tedivm/jshrink

Javascript Minifier built in PHP

76137.7M139](/packages/tedivm-jshrink)[symfony/ux-turbo

Hotwire Turbo integration for Symfony

3906.8M47](/packages/symfony-ux-turbo)[dkcwd/dkcwd-zf2-munee

Zend Framework 2 module leveraging 'munee' an asset optimisation library developed by Cody Lundquist. You can find munee at http://github.com/meenie/munee

102.1k](/packages/dkcwd-dkcwd-zf2-munee)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
