array_access_006.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. Test V8::executeString() : Enumerate 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', null, 'five');
  11. public function offsetExists($offset) {
  12. return isset($this->data[$offset]);
  13. }
  14. public function offsetGet($offset) {
  15. return $this->data[$offset];
  16. }
  17. public function offsetSet($offset, $value) {
  18. echo "set[$offset] = $value\n";
  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. $v8 = new V8Js();
  29. $v8->myarr = new MyArray();
  30. $js = <<<EOF
  31. var jsarr = [ "one", "two", "three", , "five" ];
  32. for(var i in jsarr) {
  33. var_dump(i);
  34. }
  35. for(var i in PHP.myarr) {
  36. var_dump(i);
  37. }
  38. EOF;
  39. $v8->executeString($js);
  40. ?>
  41. ===EOF===
  42. --EXPECT--
  43. string(1) "0"
  44. string(1) "1"
  45. string(1) "2"
  46. string(1) "4"
  47. string(1) "0"
  48. string(1) "1"
  49. string(1) "2"
  50. string(1) "4"
  51. ===EOF===