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.

60 lines
1.7 KiB

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