Return to returnByReference.003.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / lang |
1.1 ! misho 1: --TEST-- ! 2: Returning a reference from a function ! 3: --FILE-- ! 4: <?php ! 5: function returnConstantByValue() { ! 6: return 100; ! 7: } ! 8: ! 9: function &returnConstantByRef() { ! 10: return 100; ! 11: } ! 12: ! 13: function &returnVariableByRef() { ! 14: return $GLOBALS['a']; ! 15: } ! 16: ! 17: echo "\n---> 1. Trying to assign by reference the return value of a function that returns by value:\n"; ! 18: unset($a, $b); ! 19: $a = 4; ! 20: $b = &returnConstantByValue(); ! 21: $a++; ! 22: var_dump($a, $b); ! 23: ! 24: echo "\n---> 2. Trying to assign by reference the return value of a function that returns a constant by ref:\n"; ! 25: unset($a, $b); ! 26: $a = 4; ! 27: $b = &returnConstantByRef(); ! 28: $a++; ! 29: var_dump($a, $b); ! 30: ! 31: echo "\n---> 3. Trying to assign by reference the return value of a function that returns by ref:\n"; ! 32: unset($a, $b); ! 33: $a = 4; ! 34: $b = &returnVariableByRef(); ! 35: $a++; ! 36: var_dump($a, $b); ! 37: ! 38: ?> ! 39: --EXPECTF-- ! 40: ! 41: ---> 1. Trying to assign by reference the return value of a function that returns by value: ! 42: ! 43: Strict Standards: Only variables should be assigned by reference in %s on line 17 ! 44: int(5) ! 45: int(100) ! 46: ! 47: ---> 2. Trying to assign by reference the return value of a function that returns a constant by ref: ! 48: ! 49: Notice: Only variable references should be returned by reference in %s on line 7 ! 50: int(5) ! 51: int(100) ! 52: ! 53: ---> 3. Trying to assign by reference the return value of a function that returns by ref: ! 54: int(5) ! 55: int(5)