Return to returnByReference.008.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / tests / lang |
1.1 ! misho 1: --TEST-- ! 2: Returning a reference from a non-static method via another non-static method ! 3: --INI-- ! 4: error_reporting = E_ALL & ~E_STRICT ! 5: --FILE-- ! 6: <?php ! 7: class C { ! 8: function returnConstantByValue() { ! 9: return 100; ! 10: } ! 11: ! 12: function &returnConstantByRef() { ! 13: return 100; ! 14: } ! 15: ! 16: function &returnVariableByRef() { ! 17: return $GLOBALS['a']; ! 18: } ! 19: ! 20: function &returnFunctionCallByRef($functionToCall) { ! 21: return $this->$functionToCall(); ! 22: } ! 23: } ! 24: $c = new C; ! 25: ! 26: echo "\n---> 1. Via a return by ref function call, assign by reference the return value of a function that returns by value:\n"; ! 27: unset($a, $b); ! 28: $a = 4; ! 29: $b = &$c->returnFunctionCallByRef('returnConstantByValue'); ! 30: $a++; ! 31: var_dump($a, $b); ! 32: ! 33: 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"; ! 34: unset($a, $b); ! 35: $a = 4; ! 36: $b = &$c->returnFunctionCallByRef('returnConstantByRef'); ! 37: $a++; ! 38: var_dump($a, $b); ! 39: ! 40: echo "\n---> 3. Via a return by ref function call, assign by reference the return value of a function that returns by ref:\n"; ! 41: unset($a, $b); ! 42: $a = 4; ! 43: $b = &$c->returnFunctionCallByRef('returnVariableByRef'); ! 44: $a++; ! 45: var_dump($a, $b); ! 46: ! 47: ?> ! 48: --EXPECTF-- ! 49: ! 50: ---> 1. Via a return by ref function call, assign by reference the return value of a function that returns by value: ! 51: ! 52: Notice: Only variable references should be returned by reference in %s on line 16 ! 53: int(5) ! 54: int(100) ! 55: ! 56: ---> 2. Via a return by ref function call, assign by reference the return value of a function that returns a constant by ref: ! 57: ! 58: Notice: Only variable references should be returned by reference in %s on line 8 ! 59: int(5) ! 60: int(100) ! 61: ! 62: ---> 3. Via a return by ref function call, assign by reference the return value of a function that returns by ref: ! 63: int(5) ! 64: int(5)