array_access_basic2.phpt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if (PHP_VERSION_ID < 80000) {
  10. class MyArray implements ArrayAccess, Countable {
  11. private $data = array('one', 'two', 'three');
  12. public function offsetExists($offset) {
  13. return isset($this->data[$offset]);
  14. }
  15. public function offsetGet($offset) {
  16. return $this->data[$offset];
  17. }
  18. public function offsetSet($offset, $value) {
  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. }
  28. } else {
  29. class MyArray implements ArrayAccess, Countable {
  30. private $data = array('one', 'two', 'three');
  31. public function offsetExists($offset): bool {
  32. return isset($this->data[$offset]);
  33. }
  34. public function offsetGet(mixed $offset): mixed {
  35. return $this->data[$offset];
  36. }
  37. public function offsetSet(mixed $offset, mixed $value): void {
  38. $this->data[$offset] = $value;
  39. }
  40. public function offsetUnset(mixed $offset): void {
  41. throw new Exception('Not implemented');
  42. }
  43. public function count(): int {
  44. return count($this->data);
  45. }
  46. }
  47. }
  48. $myarr = new MyArray();
  49. $myarr[0] = 'three';
  50. $js = <<<EOJS
  51. var_dump(PHP.myarr[2]);
  52. PHP.myarr[2] = 'one';
  53. var_dump(PHP.myarr[2]);
  54. var_dump(PHP.myarr.join(','));
  55. EOJS;
  56. $v8 = new V8Js();
  57. $v8->myarr = $myarr;
  58. $v8->executeString($js);
  59. var_dump($myarr[2]);
  60. ?>
  61. ===EOF===
  62. --EXPECT--
  63. string(5) "three"
  64. string(3) "one"
  65. string(13) "three,two,one"
  66. string(3) "one"
  67. ===EOF===