-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathjs-construct-with-ctor.phpt
59 lines (47 loc) · 1.1 KB
/
js-construct-with-ctor.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
--TEST--
Test V8::executeString() : Test PHP object construction controlled by JavaScript (with ctor)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$v8 = new V8Js();
class Greeter {
protected $_name = null;
function __construct($name) {
echo "ctor called (php)\n";
$this->_name = $name;
}
function sayHello() {
echo "Hello ".$this->_name."\n";
}
}
$v8->greeter = new Greeter("John");
$v8->executeString('
function JsGreeter(name) {
print("ctor called (js)\n");
this.name = name;
};
JsGreeter.prototype.sayHello = function() {
print("Hello " + this.name + "\n");
};
jsGreeter = new JsGreeter("Paul");
jsGreeter.sayHello();
jsGreeterNg = new jsGreeter.constructor("George");
jsGreeterNg.sayHello();
// ----- now the same using v8Js -----
PHP.greeter.sayHello();
var ngGreeter = new PHP.greeter.constructor("Ringo");
ngGreeter.sayHello();
');
?>
===EOF===
--EXPECT--
ctor called (php)
ctor called (js)
Hello Paul
ctor called (js)
Hello George
Hello John
ctor called (php)
Hello Ringo
===EOF===