1--TEST-- 2Pass function and method calls by reference and by value. 3--FILE-- 4<?php 5class C { 6 static function sreturnVal() { 7 global $a; 8 return $a; 9 } 10 11 static function &sreturnReference() { 12 global $a; 13 return $a; 14 } 15 16 function returnVal() { 17 global $a; 18 return $a; 19 } 20 21 function &returnReference() { 22 global $a; 23 return $a; 24 } 25} 26 27function returnVal() { 28 global $a; 29 return $a; 30} 31 32function &returnReference() { 33 global $a; 34 return $a; 35} 36 37 38 39function foo(&$ref) { 40 var_dump($ref); 41 $ref = "changed"; 42} 43 44 45echo "Pass a function call that returns a value:\n"; 46$a = "original"; 47foo(returnVal()); 48var_dump($a); 49 50echo "Pass a function call that returns a reference:\n"; 51$a = "original"; 52foo(returnReference()); 53var_dump($a); 54 55 56echo "\nPass a static method call that returns a value:\n"; 57$a = "original"; 58foo(C::sreturnVal()); 59var_dump($a); 60 61echo "Pass a static method call that returns a reference:\n"; 62$a = "original"; 63foo(C::sreturnReference()); 64var_dump($a); 65 66 67$myC = new C; 68echo "\nPass a method call that returns a value:\n"; 69$a = "original"; 70foo($myC->returnVal()); 71var_dump($a); 72 73echo "Pass a method call that returns a reference:\n"; 74$a = "original"; 75foo($myC->returnReference()); 76var_dump($a); 77 78?> 79--EXPECTF-- 80Pass a function call that returns a value: 81 82Notice: Only variables should be passed by reference in %s on line 44 83string(8) "original" 84string(8) "original" 85Pass a function call that returns a reference: 86string(8) "original" 87string(7) "changed" 88 89Pass a static method call that returns a value: 90 91Notice: Only variables should be passed by reference in %s on line 55 92string(8) "original" 93string(8) "original" 94Pass a static method call that returns a reference: 95string(8) "original" 96string(7) "changed" 97 98Pass a method call that returns a value: 99 100Notice: Only variables should be passed by reference in %s on line 67 101string(8) "original" 102string(8) "original" 103Pass a method call that returns a reference: 104string(8) "original" 105string(7) "changed" 106