Since objects are passed by reference by default now, is there maybe some special case when &$obj
would make sense?
相关问题
- Views base64 encoded blob in HTML with PHP
- how to define constructor for Python's new Nam
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Do the Java Integer and Double objects have unnece
There are situations where you add & in front of function name, to return any value as a reference.
To call those function we need to add & in front of object.
If we add & in front of object, then it will return value as reference otherwise it will only return a copy of that variable.
Objects use a different reference mechanism.
&$object
is more a reference of a reference. You can't really compare them both. See Objects and references:&$object
is something else than$object
. I'll give you an example:I won't answer the question if it makes sense, or if there is a need. These are opinion based questions. You can definitely live without the
&
reference on objects, as you could without objects at all. The existence of two mechanisms is a consequence of PHP's backward compatibility.