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.

55 lines
1.3 KiB

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