array_access_basic2.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. Test V8::executeString() : Check array access setter behaviour
  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. return $this->data[$offset];
  16. }
  17. public function offsetSet($offset, $value) {
  18. $this->data[$offset] = $value;
  19. }
  20. public function offsetUnset($offset) {
  21. throw new Exception('Not implemented');
  22. }
  23. public function count() {
  24. return count($this->data);
  25. }
  26. }
  27. $myarr = new MyArray();
  28. $myarr[0] = 'three';
  29. $js = <<<EOJS
  30. var_dump(PHP.myarr[2]);
  31. PHP.myarr[2] = 'one';
  32. var_dump(PHP.myarr[2]);
  33. var_dump(PHP.myarr.join(','));
  34. EOJS;
  35. $v8 = new V8Js();
  36. $v8->myarr = $myarr;
  37. $v8->executeString($js);
  38. var_dump($myarr[2]);
  39. ?>
  40. ===EOF===
  41. --EXPECT--
  42. string(5) "three"
  43. string(3) "one"
  44. string(13) "three,two,one"
  45. string(3) "one"
  46. ===EOF===