array_access.phpt 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --TEST--
  2. Test V8::executeString() : Check ArrayAccess interface wrapping
  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. public function offsetExists($offset) {
  11. return $offset >= 0 && $offset <= 20;
  12. }
  13. public function offsetGet($offset) {
  14. return 19 - $offset;
  15. }
  16. public function offsetSet($offset, $value) {
  17. throw new Exception('Not implemented');
  18. }
  19. public function offsetUnset($offset) {
  20. throw new Exception('Not implemented');
  21. }
  22. public function count() {
  23. return 20;
  24. }
  25. }
  26. $myarr = new MyArray();
  27. var_dump(count($myarr));
  28. var_dump($myarr[5]);
  29. $js = <<<EOJS
  30. var_dump(PHP.myarr.constructor.name);
  31. var_dump(PHP.myarr.length);
  32. var_dump(PHP.myarr[5]);
  33. EOJS;
  34. $v8 = new V8Js();
  35. $v8->myarr = (object) $myarr;
  36. $v8->executeString($js);
  37. ?>
  38. ===EOF===
  39. --EXPECT--
  40. int(20)
  41. int(14)
  42. string(11) "ArrayAccess"
  43. int(20)
  44. int(14)
  45. ===EOF===