Skip to content

Latest commit

 

History

History

README.md

pjs

Embed QuickJS-ng in PHP to run JavaScript.

  • Pjs\Runtime — JS runtime environment
  • Pjs\Context — evaluate JS code ($ctx->eval("1+1"))
  • Pjs\Value — wraps JS return values, implements Stringable
  • Pjs\Exception — JS exceptions thrown as PHP exceptions

Run

zig build test

Custom PHP include path:

zig build test -Dphp-include-dir=/usr/include/php8.4

Tests

PHPT tests are located in tests/. Run with:

php run-tests.php

Manually

# Build
zig build

# Run JS evaluation
php -dextension=./modules/pjs.so -r '
$rt = new Pjs\Runtime();
$ctx = new Pjs\Context($rt);
var_dump($ctx->eval("1+1"));
'