PHP: Only Variables Should Be Passed by Reference

Last week i got this error while doing some coding with a new library. And at first i didn’t quite get what was causing this. The line in question looked like

$url = reset($file->getPaths());

So how can that throw an error like “Only variables should be passed by reference” you might ask? Well as it turns out to be. PHP functions don’t like arguments returned from another function. As with this case. The ->getPaths() method holds a reference to the returned array. Which it shouldn’t but that’s another thing.

So i guess from now i will doing the thing below. Or check for references beforehand!

$paths = $file->getPaths();
$url = reset($paths);
comments powered by Disqus