1--TEST-- 2Bug #33136 (method offsetSet in class extended from ArrayObject crash PHP) 3--FILE-- 4<?php 5 6class Collection extends ArrayObject 7{ 8 private $data; 9 10 function __construct() 11 { 12 $this->data = array(); 13 parent::__construct($this->data); 14 } 15 16 function offsetGet($index): mixed 17 { 18 echo __METHOD__ . "($index)\n"; 19 return parent::offsetGet($index); 20 } 21 22 function offsetSet($index, $value): void 23 { 24 echo __METHOD__ . "(" . (is_null($index) ? "NULL" : $index) . ",$value)\n"; 25 parent::offsetSet($index, $value); 26 } 27} 28 29echo "\n\nInitiate Obj\n"; 30$arrayObj = new Collection(); 31 32echo "Assign values\n"; 33 34$arrayObj[] = "foo"; 35var_dump($arrayObj[0]); 36 37$arrayObj[] = "bar"; 38var_dump($arrayObj[0]); 39var_dump($arrayObj[1]); 40 41$arrayObj["foo"] = "baz"; 42var_dump($arrayObj["foo"]); 43 44print_r($arrayObj); 45 46var_dump(count($arrayObj)); 47 48?> 49--EXPECT-- 50Initiate Obj 51Assign values 52Collection::offsetSet(NULL,foo) 53Collection::offsetGet(0) 54string(3) "foo" 55Collection::offsetSet(NULL,bar) 56Collection::offsetGet(0) 57string(3) "foo" 58Collection::offsetGet(1) 59string(3) "bar" 60Collection::offsetSet(foo,baz) 61Collection::offsetGet(foo) 62string(3) "baz" 63Collection Object 64( 65 [data:Collection:private] => Array 66 ( 67 ) 68 69 [storage:ArrayObject:private] => Array 70 ( 71 [0] => foo 72 [1] => bar 73 [foo] => baz 74 ) 75 76) 77int(3) 78