array_access.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. var_dump(PHP.myarr.join(', '));
  34. EOJS;
  35. $v8 = new V8Js();
  36. $v8->myarr = (object) $myarr;
  37. $v8->executeString($js);
  38. ?>
  39. ===EOF===
  40. --EXPECT--
  41. int(20)
  42. int(14)
  43. string(5) "Array"
  44. int(20)
  45. int(14)
  46. string(68) "19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0"
  47. ===EOF===