Skip to content

FibonacciFox/jphp-graaljs-ext

Repository files navigation

English / Русский


jphp-graaljs-ext

version 1.0.0, created by JPPM.

GraalVM JavaScript API

Install

jppm add jphp-graaljs-ext@1.0.0

API

Classes

php\graaljs

<?php
Class ExtClass {
    
    $id = 123;
    $text = 'Hello Jphp';
    
    public function test(){
        return "jphp string";
    }
}
?>
<?php
$Context = new Context();
    $newContext = $Context->newBuilder([])->allowAllAccess(true)->build();
    $newContext->getBindings("js")->putMember("ExtClass", new ExtClass());    
    $newContext->eval("js","print(ExtClass.getValue('id'));");
    $newContext->eval("js","ExtClass.setValue('id', 1000);");
    $newContext->eval("js","print(ExtClass.getValue('id'));");
    $newContext->eval("js","let func = ExtClass.invoke('test'); print(func);");
?>