mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 18:41:52 +00:00
f6a6d1e4b5
Use the NamedPropertyHandler feature of v8 to wrap accesses to PHP properties and methods from JavaScript. This enables us to support property set/delete/query. The `in` and `delete` operators in JavaScript work like the `isset()` and `unset()` functions in PHP. In particular, a PHP property with a null value will not be `in` the JavaScript object. (This holds when enumerating all properties of an object as well.) Because JavaScript has a single namespace for both properties and methods, we allow the use of the `__call` method on a PHP object (even if the PHP class does not natively define the `__call` magic function) in order to unambiguously invoke a method. Similarly, you can prefix a property name with `$` to unambiguously access the property. (When enumerating all properties, properties are `$`-prefixed in order to ensure they are not conflated with method names.)
51 lines
918 B
PHP
51 lines
918 B
PHP
--TEST--
|
|
Test V8::executeString() : Object passed from PHP
|
|
--SKIPIF--
|
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
|
--FILE--
|
|
<?php
|
|
|
|
$JS = <<< EOT
|
|
function dump(a)
|
|
{
|
|
for (var i in a) {
|
|
var val = a[i];
|
|
print(i + ' => ' + val + "\\n");
|
|
}
|
|
}
|
|
function test()
|
|
{
|
|
dump(PHP.myobj);
|
|
PHP.myobj.foo = 'CHANGED';
|
|
PHP.myobj.mytest();
|
|
}
|
|
test();
|
|
print(PHP.myobj.foo + "\\n");
|
|
EOT;
|
|
|
|
// Test class
|
|
class Testing
|
|
{
|
|
public $foo = 'ORIGINAL';
|
|
private $my_private = 'arf'; // Should not show in JS side
|
|
protected $my_protected = 'argh'; // Should not show in JS side
|
|
|
|
function mytest() { echo 'Here be monsters..', "\n"; }
|
|
}
|
|
|
|
$a = new V8Js();
|
|
$a->myobj = new Testing();
|
|
$a->executeString($JS, "test.js");
|
|
|
|
// Check that variable has not been modified
|
|
var_dump($a->myobj->foo);
|
|
?>
|
|
===EOF===
|
|
--EXPECT--
|
|
mytest => function () { [native code] }
|
|
$foo => ORIGINAL
|
|
Here be monsters..
|
|
CHANGED
|
|
string(7) "CHANGED"
|
|
===EOF===
|