bug33136.phpt 1.4 KB

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