return_this_basic.phpt 726 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. --TEST--
  2. Test V8::executeString() : return $this (aka fluent setters)
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. class Foo {
  8. private $foo;
  9. private $bar;
  10. public function setFoo($value)
  11. {
  12. $this->foo = $value;
  13. return $this;
  14. }
  15. public function setBar($value)
  16. {
  17. $this->bar = $value;
  18. return $this;
  19. }
  20. }
  21. $v8 = new V8Js();
  22. $v8->theFoo = new Foo();
  23. $v8->executeString(<<<EOJS
  24. var a = PHP.theFoo.setFoo(23);
  25. var b = a.setBar(42);
  26. var_dump(PHP.theFoo === a);
  27. var_dump(PHP.theFoo === b);
  28. EOJS
  29. );
  30. var_dump($v8->theFoo);
  31. ?>
  32. ===EOF===
  33. --EXPECTF--
  34. bool(true)
  35. bool(true)
  36. object(Foo)#%d (2) {
  37. ["foo":"Foo":private]=>
  38. int(23)
  39. ["bar":"Foo":private]=>
  40. int(42)
  41. }
  42. ===EOF===