Run PHP client-side in the browser or in Node.js.
Uniter is split into several NPM packages, each with a separate repository:
uniter is the main Uniter library (this repository).
It pulls in all the required components (below) to take a string of PHP code, evaluate it and return the result
with a simple API.
phptoast is the parser for Uniter. It takes PHP code as a string
phptojs is the transpiler. It takes an AST (such as the one returned by
that can then be executed.
phpcore is the minimal runtime library required for code transpiled by
phptojs to execute.
It contains some builtin PHP classes and functions, but only those that are required
Closure class or
phpruntime is the extended "full" runtime library.
After pulling in
phpcore, it installs the remaining builtin classes and functions, such as
Only a small subset of PHP's standard library has been implemented so far - please open a GitHub issue
phpruntime repository if you would like to request something that is missing.
phpcommon contains various tools that are shared between the different
packages, such as the
PHPFatalError class used by both the parser (
phptoast) and runtime (
phpify is a Browserify transform that can be used to require PHP modules
see the Uniter Symfony EventDispatcher demo.
$ npm install uniter$ node
> var php = ;> php;> php;Hello from PHP!
Environment-agnostic architecture: should run in any modern browser (IE < 9 support coming soon) and Node.js
PHP statements, constructs and operators:
functionstatements with type hinting (as syntactic sugar only: no enforcement is performed yet)
gotostatements (but no overlap support yet)
classobject support (
functionimporting and aliasing
And others... see the
Engine integration tests for more info.
You can use Uniter from the command line after installing it via NPM, eg.:
# Install Uniter globally$ npm install -g uniter# Execute PHP code$ uniter -r 'echo 7 + 2;'9# Parse PHP but just dump the AST as JSON, don't attempt to execute$ uniter -r 'echo 7 + 2;' --dump-ast
There are two supported ways of running the Mocha test suite:
Run the tests in Node.js from the command line:
cd uniter/ npm test
Run the tests in a browser by starting a Node.js server:
npm run-script webtest
You should then be able to run the tests by visiting http://127.0.0.1:6700 in a supported web browser.