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