11--TEST--
22Test V8::executeString() : Use ArrayAccess with JavaScript native push method
33--SKIPIF--
4- <?php require_once (dirname (__FILE__ ) . '/skipif.inc ' );
5-
6- if (str_starts_with (V8Js::V8_VERSION , '11.3.244.8 ' )) {
7- die ("skip V8 version known to call setter twice " );
8- }
9-
10- ?>
4+ <?php require_once (dirname (__FILE__ ) . '/skipif.inc ' ); ?>
115--INI--
126v8js.use_array_access = 1
137--FILE--
@@ -16,6 +10,10 @@ v8js.use_array_access = 1
1610class MyArray implements ArrayAccess, Countable {
1711 private $ data = Array ('one ' , 'two ' , 'three ' );
1812
13+ // V8 versions on alpine are known to call the setter twice. As a work-around we set a
14+ // flag here and print only once, so we don't fail the test because of that.
15+ private $ setterCalled = false ;
16+
1917 public function offsetExists ($ offset ): bool {
2018 return isset ($ this ->data [$ offset ]);
2119 }
@@ -25,8 +23,13 @@ class MyArray implements ArrayAccess, Countable {
2523 }
2624
2725 public function offsetSet (mixed $ offset , mixed $ value ): void {
26+ if ($ this ->setterCalled ) {
27+ return ;
28+ }
29+
2830 echo "set[ $ offset] = $ value \n" ;
2931 $ this ->data [$ offset ] = $ value ;
32+ $ this ->setterCalled = true ;
3033 }
3134
3235 public function offsetUnset (mixed $ offset ): void {
0 commit comments