PHPackages                             chenos/execjs - 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. chenos/execjs

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

chenos/execjs
=============

v0.1.0(8y ago)311355[1 issues](https://github.com/chenos/execjs/issues)PHP

Since Feb 5Pushed 8y ago3 watchersCompare

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

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

ExecJs
======

[](#execjs)

[![Build Status](https://camo.githubusercontent.com/99fe10b6d5f0d0b971b7b8b5132a38fb8e82e0e4851ea4735371779eabefaf0c/68747470733a2f2f7472617669732d63692e6f72672f6368656e6f732f657865636a732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/chenos/execjs) [![Coverage Status](https://camo.githubusercontent.com/956482324179190bd65a699c0fc9d1c3dcd2d5eb9e2497ff125eb712646bad17/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6368656e6f732f657865636a732f62616467652e7376673f6272616e63683d6d6173746572267631)](https://coveralls.io/github/chenos/execjs?branch=master)

Requirements
------------

[](#requirements)

- PHP 7.0+
- V8Js extension 2.0+

Installation
------------

[](#installation)

```
composer require chenos/execjs
```

Testing
-------

[](#testing)

```
make test

```

Example
-------

[](#example)

```
make example
```

Access

- [liquidjs](examples/liquidjs)
- [marked &amp; markdown-it](examples/markdown)
- [react](examples/react-router)
- [vue-simple](examples/vue-simple)
- [vue-router](examples/vue-router)
- [js-yaml](examples/yaml)

Usage
-----

[](#usage)

```
use Chenos\ExecJs\Context;
use Chenos\V8JsModuleLoader\ModuleLoader;

$context = new Context('PHP');

$context->getLoader()
    ->setEntryDir(__DIR__)
    ->addVendorDir(__DIR__.'/node_modules')
    ->addOverride('vue', 'vue/dist/vue.runtime.common.js')
    ;
// or
$loader = new ModuleLoader();
$loader->setEntryDir(__DIR__)
    ->addVendorDir(__DIR__.'/node_modules')
    ->addOverride('vue', 'vue/dist/vue.runtime.common.js')
    ;
$context->setLoader($loader);

$context->eval(string $script);
$context->load(string $module);
$context->require($module, string|array $identifier);
$context->set(string $key, mixed $value, $global = false);
```

API
---

[](#api)

### eval

[](#eval)

Evaluates JavaScript code represented as a string.

```
public mixed function eval(string $script, int $flags = V8Js::FLAG_NONE, int $timeLimit = 0, int $memoryLimit = 0)
```

Almost the same as `V8Js::executeString` except `$identifier` argument.

```
public mixed function V8Js::executeString(string $script, string $identifier = '', int $flags = V8Js::FLAG_NONE, int $timeLimit = 0, int $memoryLimit = 0)
```

Usage:

```
$context->eval('1+1'); // 2
```

### load

[](#load)

Evaluates JavaScript code represented from a file.

```
public mixed function load(string $module, int $flags = V8Js::FLAG_NONE, int $timeLimit = 0, int $memoryLimit = 0)
```

```
$context->load('./foo.js');
// equals
$str = $context->getLoader()->loadModule('./foo.js');
$context->eval($str);
```

### require

[](#require)

CommonJS module support to require external code.

```
public mixed function require(string $module, string|array $identifier = null)
```

Usage:

```
$yaml = $context->require('js-yaml');
$yaml->load('a: b'); // ['a' => 'b']
```

String identifier

```
$yaml = $context->require('js-yaml', 'jsyaml');
// equals
$context->eval("var jsyaml = require('js-yaml'); jsyaml;");

// usage
$yaml->load('a: b'); // ['a' => 'b']
$context->eval(sprintf('jsyaml.dump(%s)', json_encode(['a' => 'b']))); // 'a: b'
```

Array identifier

```
$context->require('js-yaml', ['load', 'dump']);
// equals
$context->eval("var {load, dump} = require('js-yaml').load;");

$context->eval("load('a: b')"); // ['a' => 'b']
$context->eval(sprintf('dump(%s)', json_encode(['a' => 'b']))); // 'a: b'

$context->require('js-yaml', ['load' => 'yamlLoad']);
// equals
$context->eval("var yamlLoad = require('js-yaml').load;");
// es6: import {load as yamlLoad} from 'js-yaml'

$context->eval("yamlLoad('a: b')"); // ['a' => 'b']
```

### set

[](#set)

Assign a property to make it accessible to the javascript context.

```
public Context function set(string $key, mixed $value, $global = false)
```

Usage:

```
$context->set('foo', 'bar');
$context->eval('PHP.foo'); // bar
$context->eval('foo'); // error undefined

$context->set('bar', 'baz', true);
$context->eval('PHP.bar'); // baz
$context->eval('bar'); // baz

$context->set('process', [
    'env' => [
        'NODE_ENV' => 'production',
    ],
], true);

$context->eval('process.env.NODE_ENV'); // production
```

Global Variables
----------------

[](#global-variables)

- exit `V8Function`
- PHP `V8Js`
- print `V8Function`
- require `V8Function`
- sleep `V8Function`
- var\_dump `V8Function`

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

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

3069d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2993310?v=4)[chenos](/maintainers/chenos)[@chenos](https://github.com/chenos)

---

Top Contributors

[![chenos](https://avatars.githubusercontent.com/u/2993310?v=4)](https://github.com/chenos "chenos (11 commits)")

---

Tags

execjsjavascriptphpphp-v8reactserver-side-renderingssrv8jsvue

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chenos-execjs/health.svg)

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

PHPackages © 2026

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