PHP-V8Js is a PHP extension for the V8 JavaScript engine. It is a re-implementation of the fantastic (though unmaintained) V8Js PHP extension.
The extension allows you to execute JavaScript code in a secure sandbox from PHP. The executed code can be restricted using a time limit and/or memory limit. This provides the possibility to execute untrusted code with confidence.
- PHP 8.0+
The extension includes builds of libv8, via the v8 crate. This makes installing the extension very simple.
| PHP -> JavaScript | JavaScript -> PHP |
|---|---|
| String -> string | string -> String |
| Bool -> bool | bool -> Bool |
| Array (numeric) -> Array | array -> Array |
| Array (string keys) -> Object | Object -> V8Object |
| Int -> Number | Number -> Float |
- Memory / time limits
- Snapshop creating and loading
- Default global functions
var_dump,sleep,exit - Default global function
print - CommonJS /
requiresupport -
setModuleLoader -
setModuleNormaliser - Subclassing V8Js
- Custom exceptions for
V8JsScriptException,V8JsMemoryLimitExceptionandV8JsTimeLimitException - Support for
V8JsScriptException::getJsLineNumberetc. - Support for
FLAG_PROPAGATE_PHP_EXCEPTIONS,V8Js::FLAG_FORCE_ARRAY - PHP INI settings
v8js.flags -
V8Js::V8_VERSIONconstant
- Support for
ArrayAccessobjects mapped into JavaScript - PHP INI settings
v8js.use_array_access,v8js.use_date,v8js.icudtl_dat_path V8Js::registerExtension
- Support for native ES modules
- Stefan Siegl of course for creating v8js, and the 37 contributors.
- David Cole for creating ext-php-rs and helping me use the library.