array_access_001.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. --TEST--
  2. Test V8::executeString() : Check ArrayAccess live binding
  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. public function push($value) {
  27. $this->data[] = $value;
  28. }
  29. }
  30. $v8 = new V8Js();
  31. $v8->myarr = new MyArray();
  32. $v8->executeString('var_dump(PHP.myarr.join(","));');
  33. /* array is "live bound", i.e. new elements just pop up on js side. */
  34. $v8->myarr->push('new');
  35. $v8->executeString('var_dump(PHP.myarr.join(","));');
  36. ?>
  37. ===EOF===
  38. --EXPECT--
  39. string(13) "one,two,three"
  40. string(17) "one,two,three,new"
  41. ===EOF===