I just thought that not only objects but also variables are copied in PHP4, so if you have a Log class that only outputs a message to a log file, doesn't it make sense to pass the message (string) by reference so that unnecessary copy is not made??
class Log
{
// this copies $message
function log($message)
{
error_log($message);
}
}
// "log me" is copied by method log()
Log::log("log me");
so shouldn't it be like
class Log
{
// this does not copy $message
function log(& $message)
{
error_log($message);
}
}
// "log me" is passed by reference, not making a copy, saving memory usage???
Log::log("log me");
Does this make sense or is it even a correct approach?? I'm sure a lot of people "log" messages to a log file using their own Log class, so I'm guessing there are tons of copies made when messages are logged and eating up a lot of memory space doing that??
This applies to not only logging, but also many methods and functions.... I've been thinking about this too much... starting to get too confused...