I have a function:
$query = "SELECT * from lol";
database_query( $query );
considering the $query
will never be changed inside the database_query function, is it good practice to use a pointer to $query
so the function doesn't need to assign more memory to a new iteration of the value passed in?
function database_query( &$query ){
//do stuff that does not affect $query
}
No, don't do this. PHP will only create another copy of the string if the value of the non-pass-by-reference parameter is changed inside of the function ("copy on write"). There is no reason to give people reading your code the wrong impression of what your function is doing by making the parameter a reference.
Also, references are not pointers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With