array_access_basic2.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. Test V8::executeString() : Check array access setter behaviour
  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. $this->data[$offset] = $value;
  19. }
  20. public function offsetUnset(mixed $offset): void {
  21. throw new Exception('Not implemented');
  22. }
  23. public function count(): int {
  24. return count($this->data);
  25. }
  26. }
  27. $myarr = new MyArray();
  28. $myarr[0] = 'three';
  29. $js = <<<EOJS
  30. var_dump(PHP.myarr[2]);
  31. PHP.myarr[2] = 'one';
  32. var_dump(PHP.myarr[2]);
  33. var_dump(PHP.myarr.join(','));
  34. EOJS;
  35. $v8 = new V8Js();
  36. $v8->myarr = $myarr;
  37. $v8->executeString($js);
  38. var_dump($myarr[2]);
  39. ?>
  40. ===EOF===
  41. --EXPECT--
  42. string(5) "three"
  43. string(3) "one"
  44. string(13) "three,two,one"
  45. string(3) "one"
  46. ===EOF===