array_access.phpt 1.2 KB

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