Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/return_this_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--TEST--
Test V8::executeString() : return $this (aka fluent setters)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php

class Foo {
private $foo;
private $bar;

public function setFoo($value)
{
$this->foo = $value;
return $this;
}

public function setBar($value)
{
$this->bar = $value;
return $this;
}
}

$v8 = new V8Js();
$v8->theFoo = new Foo();

$v8->executeString(<<<EOJS
var a = PHP.theFoo.setFoo(23);
var b = a.setBar(42);

var_dump(PHP.theFoo === a);
var_dump(PHP.theFoo === b);
EOJS
);

var_dump($v8->theFoo);

?>
===EOF===
--EXPECTF--
bool(true)
bool(true)
object(Foo)#%d (2) {
["foo":"Foo":private]=>
int(23)
["bar":"Foo":private]=>
int(42)
}
===EOF===
3 changes: 3 additions & 0 deletions v8js_object_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ static void v8js_call_php_func(zval *value, zend_class_entry *ce, zend_function
} else {
v8js_terminate_execution(isolate);
}
} else if (retval_ptr == value) {
// special case: "return $this"
return_value = info.Holder();
} else if (retval_ptr != NULL) {
return_value = zval_to_v8js(retval_ptr, isolate TSRMLS_CC);
}
Expand Down