array_access_005.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --TEST--
  2. Test V8::executeString() : Export __invoke method on ArrayAccess objects
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --INI--
  6. v8js.use_array_access = 1
  7. --FILE--
  8. <?php
  9. class MyArray implements ArrayAccess, Countable {
  10. private $data = Array('one', 'two', 'three');
  11. public function offsetExists($offset) {
  12. return isset($this->data[$offset]);
  13. }
  14. public function offsetGet($offset) {
  15. return $this->data[$offset];
  16. }
  17. public function offsetSet($offset, $value) {
  18. echo "set[$offset] = $value\n";
  19. $this->data[$offset] = $value;
  20. }
  21. public function offsetUnset($offset) {
  22. throw new Exception('Not implemented');
  23. }
  24. public function count() {
  25. return count($this->data);
  26. }
  27. public function __invoke() {
  28. echo "__invoke called!\n";
  29. }
  30. }
  31. $v8 = new V8Js();
  32. $v8->myarr = new MyArray();
  33. $v8->executeString('PHP.myarr();');
  34. $v8->executeString('var_dump(PHP.myarr.length);');
  35. $v8->executeString('var_dump(PHP.myarr.join(", "));');
  36. ?>
  37. ===EOF===
  38. --EXPECT--
  39. __invoke called!
  40. int(3)
  41. string(15) "one, two, three"
  42. ===EOF===