array_access_005.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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): bool {
  12. return isset($this->data[$offset]);
  13. }
  14. public function offsetGet(mixed $offset): mixed {
  15. return $this->data[$offset];
  16. }
  17. public function offsetSet(mixed $offset, mixed $value): void {
  18. echo "set[$offset] = $value\n";
  19. $this->data[$offset] = $value;
  20. }
  21. public function offsetUnset(mixed $offset): void {
  22. throw new Exception('Not implemented');
  23. }
  24. public function count(): int {
  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===