PHPackages                             lechimp-p/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. lechimp-p/php2js

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

lechimp-p/php2js
================

Compiles sane PHP to javascript.

0.1.0(7y ago)514[1 PRs](https://github.com/lechimp-p/php2js/pulls)GPL-3.0-or-laterPHP

Since May 5Pushed 2y ago2 watchersCompare

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

READMEChangelog (1)Dependencies (6)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/b29e13787ad39db6cf774fa3f80022e03a6edae17f4693a8413a82f53f5064cc/68747470733a2f2f6170692e7472617669732d63692e636f6d2f6c656368696d702d702f706870326a732e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/lechimp-p/php2js)

php2js - Compiles sane PHP to JavaScript
========================================

[](#php2js---compiles-sane-php-to-javascript)

**php2js makes it possible that you write client side scripts in your favorite scripting language.**

*This currently is in a proof of concept stage and in now way ready for prime time.*

Usage
-----

[](#usage)

*Currently this only supports enough functionality to make the HelloWorld-example happen.*

- Write your client-side script in PHP. Your main file is supposed to contain one class implementing `JS\Script`. Dependencies to JS-API can be declared in the constructor of said class and will be passed by the runtime.
- Compile your script using `php php2js.php compile $SCRIPT`. This will output some js that you can include to your page. The compiler will resolve internal dependencies and use a composer.json to pull in further files.
- Since this is not supposed to support every PHP-API and language construct, the compiler may yell at you if you use some stuff it does not want to compile. Reasonable and sane modern PHP should compile.

Rationale
---------

[](#rationale)

*Again, this currently is a proof of concept.*

When working on a (possibly old) PHP-applications users typically expect features that need to be implemented client-side nowadays. This challenges communities of PHP-developers in two different ways.

On the one hand, client-side demands new skills and knowledge. While we may expect every contemporay PHP-developer to know its share of jquery, more complex applications demand for means that jquery never meant to provide. When switching to modern js-frameworks, like React or Vue, to implement requirements of these more complex apps, we either demand PHP-developers to acquire the skills and knowledge to use these tools or we need to add new developers to our projects that already have these skills. In both scenarios we will add new layers of complexity to our project.

On the other hand, PHP-projects will already have some code which possibly would need to be rewritten for the client-side. If, e.g., one would want to perform some validation on input on the client-side to provide quick feedback to users, the according code would need to be rewritten in javascript (or another language) and server- and client-side validation would need to be hold in sync afterwards. This will be a handicap for every PHP-project compared to projects written in language that work on client- and server-side. After all, two languages and tool chains need to be supported.

**php2js** attempts to solve these problems by providing a way to write client-side code in PHP, just as server-side code. Client-side code thus can be subject to the same procedures (e.g. testing or static analysis) like server-side code and can be compiled to JavaScript before deployment.

While doing this, **php2js** does not attempt to implement each and every feature or API of PHP, thus being able to compile to JavaScript directly instead of providing a PHP-runtime in JavaScript or figuring out (e.g.) how file-operations can be emulated in the browser.

Outlook
-------

[](#outlook)

*We are not there yet, this is a proof of concept!!1*

The idea for this compiler was born when working on the UI-framework of the [ILIAS Open Source LMS](https://www.ilias.de) ([on GitHub](https://www.github.com/ILIAS-eLearning/ILIAS%22)). This proof of concept will be used in discussions in the community how to proceed with the client-side functionality of the ILIAS-UI-framework. If this is ever put to real work, we most probably will add another layer over the bare JS-APIs implemented by this compiler that allow to add client-side functionality to the ILIAS-UI-framework in a structured way. This compiler thus is intended to be complemented by a client-side-framework written in PHP.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2567d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/70fc111a624b0bdaf2e14adcdb8c484bc7fd18cc0403279aea387af143ba9fcc?d=identicon)[lechimp-p](/maintainers/lechimp-p)

---

Top Contributors

[![lechimp-p](https://avatars.githubusercontent.com/u/5079221?v=4)](https://github.com/lechimp-p "lechimp-p (227 commits)")

---

Tags

clientjavascriptcompiler

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[roave/backward-compatibility-check

Tool to compare two revisions of a public API to check for BC breaks

5953.3M56](/packages/roave-backward-compatibility-check)[phpro/soap-client

A general purpose SoapClient library

8885.6M46](/packages/phpro-soap-client)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4723.6M20](/packages/coenjacobs-mozart)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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