bug40833.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. --TEST--
  2. Bug #40833 (Crash when using unset() on an ArrayAccess object retrieved via __get)
  3. --FILE--
  4. <?php
  5. class entity
  6. {
  7. private $data;
  8. private $modified;
  9. function __get($name)
  10. {
  11. if ( isset($this->data[$name]) )
  12. return $this->data[$name];
  13. else
  14. return $this->data[$name] = new set($this);
  15. }
  16. function __set($name, $value)
  17. {
  18. $this->modified[$name] = $value;
  19. }
  20. }
  21. class set implements ArrayAccess
  22. {
  23. private $entity;
  24. function __construct($entity)
  25. {
  26. $this->entity = $entity;
  27. $this->entity->whatever = $this;
  28. }
  29. function clear() {
  30. $this->entity->whatever = null;
  31. }
  32. function offsetUnset($offset): void
  33. {
  34. $this->clear();
  35. // $this->entity->{$this->name} = null;
  36. }
  37. function offsetSet($offset, $value): void
  38. {
  39. }
  40. function offsetGet($offset): mixed
  41. {
  42. return 'Bogus ';
  43. }
  44. function offsetExists($offset): bool
  45. {
  46. }
  47. }
  48. $entity = new entity();
  49. echo($entity->whatever[0]);
  50. //This will crash
  51. // $entity->whatever->clear();
  52. unset($entity->whatever[0]);
  53. //This will not crash (comment previous & uncomment this to test
  54. // $test = $entity->whatever; unset($test[0]);
  55. echo($entity->whatever[0]);
  56. echo "ok\n";
  57. ?>
  58. --EXPECT--
  59. Bogus Bogus ok