dereference_012.phpt 675 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. Testing array dereferencing on return of a method with and without reference
  3. --FILE--
  4. <?php
  5. class foo {
  6. static $x = array();
  7. public function &a() {
  8. self::$x = array(1, 2, 3);
  9. return self::$x;
  10. }
  11. public function b() {
  12. $x = array(1);
  13. $x[] = 2;
  14. return $x;
  15. }
  16. }
  17. $foo = new foo;
  18. // Changing the static variable
  19. $foo->a()[0] = 2;
  20. var_dump($foo::$x);
  21. $foo->b()[] = new stdClass;
  22. $h = $foo->b();
  23. var_dump($h);
  24. $h[0] = 3;
  25. var_dump($h);
  26. ?>
  27. --EXPECT--
  28. array(3) {
  29. [0]=>
  30. int(2)
  31. [1]=>
  32. int(2)
  33. [2]=>
  34. int(3)
  35. }
  36. array(2) {
  37. [0]=>
  38. int(1)
  39. [1]=>
  40. int(2)
  41. }
  42. array(2) {
  43. [0]=>
  44. int(3)
  45. [1]=>
  46. int(2)
  47. }