array_access_008.phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. --TEST--
  2. Test V8::executeString() : in array (isset) behaviour of ArrayAccess
  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', null, '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. unset($this->data[$offset]);
  23. }
  24. public function count() {
  25. return max(array_keys($this->data)) + 1;
  26. }
  27. }
  28. } else {
  29. class MyArray implements ArrayAccess, Countable {
  30. private $data = Array('one', null, '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. unset($this->data[$offset]);
  42. }
  43. public function count(): int {
  44. return max(array_keys($this->data)) + 1;
  45. }
  46. }
  47. }
  48. $v8 = new V8Js();
  49. $v8->myarr = new MyArray();
  50. $js = <<<EOF
  51. var jsarr = [ "one", , "three" ];
  52. var_dump(0 in jsarr);
  53. var_dump(1 in jsarr);
  54. var_dump(0 in PHP.myarr);
  55. var_dump(1 in PHP.myarr);
  56. EOF;
  57. $v8->executeString($js);
  58. ?>
  59. ===EOF===
  60. --EXPECT--
  61. bool(true)
  62. bool(false)
  63. bool(true)
  64. bool(false)
  65. ===EOF===