Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between function and &function [duplicate]

Tags:

php

function fun1();
function &fun1();

What is the difference between these??

like image 745
Joe Smack Avatar asked Dec 04 '10 19:12

Joe Smack


1 Answers

If you put an ampersand before your function name, the function will return a reference to a variable instead of the value.

Returning by reference is useful when you want to use a function to find to which variable a reference should be bound. Do not use return-by-reference to increase performance. The engine will automatically optimize this on its own. Only return references when you have a valid technical reason to do so.

From the PHP Manual on Returning References.

like image 59
Evan Mulawski Avatar answered Nov 04 '22 06:11

Evan Mulawski