array_access_007.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. Test V8::executeString() : Delete (unset) ArrayAccess keys
  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. if(!$this->offsetExists($offset)) {
  16. return null;
  17. }
  18. return $this->data[$offset];
  19. }
  20. public function offsetSet($offset, $value) {
  21. $this->data[$offset] = $value;
  22. }
  23. public function offsetUnset($offset) {
  24. unset($this->data[$offset]);
  25. }
  26. public function count() {
  27. return max(array_keys($this->data)) + 1;
  28. }
  29. }
  30. $v8 = new V8Js();
  31. $v8->myarr = new MyArray();
  32. $js = <<<EOF
  33. var jsarr = [ "one", "two", "three" ];
  34. delete jsarr[1];
  35. var_dump(jsarr.join(","));
  36. delete PHP.myarr[1];
  37. var_dump(PHP.myarr.join(","));
  38. EOF;
  39. $v8->executeString($js);
  40. ?>
  41. ===EOF===
  42. --EXPECT--
  43. string(10) "one,,three"
  44. string(10) "one,,three"
  45. ===EOF===