Hi there folks!
I was receiving the following error on a gallery script whose server's PHP got upgraded:
Strict Standards: Only variables should be passed by reference in /home/higher/public_html/gallery/includes/mg2_functions.php on line 650
function medium($name) {
$ext = strrchr($name, '.');
if($ext !== false) {
$name = substr($name, 0, -strlen($ext)) . "_medium." . end(explode('.',$name)); <~~ Problem line
}
return $name;
}
function thumb($name) {
$ext = strrchr($name, '.');
if($ext !== false) {
$name = substr($name, 0, -strlen($ext)) . "_thumb." . end(explode('.',$name)); <~~ Problem line
}
return $name;
}
I did some googling and it looked like the issue was with the end / explode in those two lines so I moved those two outside of the line, like so:
function thumb($name) {
$ext = strrchr($name, '.');
if($ext !== false) {
$extension = end(explode('.',$name));
$name = substr($name, 0, -strlen($ext)) . "_thumb." . $extension;
}
return $name;
}
Which effectively moved the error to the new line, so I broke that up into two:
function thumb($name) {
$ext = strrchr($name, '.');
if($ext !== false) {
$extension = explode('.',$name);
$extension = end($extension);
$name = substr($name, 0, -strlen($ext)) . "_thumb." . $extension;
}
return $name;
}
Which got rid of the error. I'm wondering though, what's the deal with this error? Why is it important to only perform this type of thing on a var and not on a similar function nested inside it?
It's just a curiosity thing really. I don't know why it's a no-no the way it was handled initially.
Thanks for your time!