In C++ when you want a function to be able to read from an object, but not modify it, you pass a const reference to the function. What is the equivalent way of doing this in php?
I know objects in php5 are passed by reference by default, but for readability I think I will continue to use the ampersand before the variable name, like this:
function foo(&$obj)
{
}
If you want to pass an object but not by reference you can
clonethe object beforehand.That’s your call but I find that would simply make it read more like C++. Alternativly, you can show that an object is being passed in by using type-hinting in your function definition:
Once it’s clear that
$objis an object it can be assumed that it’s being passed by reference.