You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

  1. --TEST--
  2. Returning a reference from a static method via another static method
  3. --INI--
  4. error_reporting = E_ALL & ~E_STRICT
  5. --FILE--
  6. <?php
  7. class C {
  8. static function returnConstantByValue() {
  9. return 100;
  10. }
  11. static function &returnConstantByRef() {
  12. return 100;
  13. }
  14. static function &returnVariableByRef() {
  15. return $GLOBALS['a'];
  16. }
  17. static function &returnFunctionCallByRef($functionToCall) {
  18. return C::$functionToCall();
  19. }
  20. }
  21. echo "\n---> 1. Via a return by ref function call, assign by reference the return value of a function that returns by value:\n";
  22. unset($a, $b);
  23. $a = 4;
  24. $b = &C::returnFunctionCallByRef('returnConstantByValue');
  25. $a++;
  26. var_dump($a, $b);
  27. echo "\n---> 2. Via a return by ref function call, assign by reference the return value of a function that returns a constant by ref:\n";
  28. unset($a, $b);
  29. $a = 4;
  30. $b = &C::returnFunctionCallByRef('returnConstantByRef');
  31. $a++;
  32. var_dump($a, $b);
  33. echo "\n---> 3. Via a return by ref function call, assign by reference the return value of a function that returns by ref:\n";
  34. unset($a, $b);
  35. $a = 4;
  36. $b = &C::returnFunctionCallByRef('returnVariableByRef');
  37. $a++;
  38. var_dump($a, $b);
  39. ?>
  40. --EXPECTF--
  41. ---> 1. Via a return by ref function call, assign by reference the return value of a function that returns by value:
  42. Notice: Only variable references should be returned by reference in %s on line 16
  43. int(5)
  44. int(100)
  45. ---> 2. Via a return by ref function call, assign by reference the return value of a function that returns a constant by ref:
  46. Notice: Only variable references should be returned by reference in %s on line 8
  47. int(5)
  48. int(100)
  49. ---> 3. Via a return by ref function call, assign by reference the return value of a function that returns by ref:
  50. int(5)
  51. int(5)