In C++ passing variables from functions to the function caller can always have better performance when returning a variable by const & (constant reference).
class A {
private:
std::string name;
public:
inline const std::string& getName() { return this->name; } const
}
I am wondering if returning variables from a function in PHP as a reference can have better performance then just returning a variable like normal.
In C++ I understand that when you return a variable without const ref it copies the data into the variable that you are setting it to. So you will have two locations in memory with the same data.
But when you pass around references, you are just passing the address in memory to the same data.
Is this how it works in PHP? Or does PHP do optimization regardless?
Will the following function run faster if it is written like so? Returning a reference?
public function &getDatabaseConnection() { return $this->databaseConnection; }
Or does it not make much of a difference?