3 ms·
Unfortunately, there are some bugs with the variable passing. You should be able to pass an array of variables to the V8js object and have access to them under
by giberson 15y ago
Unfortunately, there are some bugs with the variable passing. You should be able to pass an array of variables to the V8js object and have access to them under PHP js object. However, the values are currently set to null.
In my experimentation I wanted to see [in php after js execution] all the variables created in the global scope. There are two ways to do it, pass the flag to the V8js constructor to make executeString return associative arrays and add "this;" to the tail of the scripts you execute. Or, append "JSON.stringify(this);" to the tail of the scripts.
The first method will return everything including references to print, var_dump, sleep and exit methods that are bridged from PHP.
The stringify method will give you just the variables without the method references but tends to leave you with empty arrays if all your array indices point to null values. Which is misleading if the result is "someVal: {}", verses "someVal: {'foo': null, 'bar': null}".
What it misses most, is the ability to bridge your own method calls. Would be nice to be able to register a method call in JS that executes a user defined PHP function.