objects_032.phpt 538 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. --TEST--
  2. Covariant return-by-ref constraints
  3. --FILE--
  4. <?php
  5. class A implements ArrayAccess {
  6. public $foo = array();
  7. public function &offsetGet($n): mixed {
  8. return $this->foo[$n];
  9. }
  10. public function offsetSet($n, $v): void {
  11. }
  12. public function offsetUnset($n): void {
  13. }
  14. public function offsetExists($n): bool {
  15. }
  16. }
  17. $a = new A;
  18. $a['foo']['bar'] = 2;
  19. var_dump($a);
  20. ?>
  21. --EXPECT--
  22. object(A)#1 (1) {
  23. ["foo"]=>
  24. array(1) {
  25. ["foo"]=>
  26. array(1) {
  27. ["bar"]=>
  28. int(2)
  29. }
  30. }
  31. }