The function needs to continue to return its result by reference. The two places it contain return false should return a variable. By setting $pages to false at the top of the function, we can just return $pages instead of false.

"need" may be the wrong word - since $pages isn't bound to a global, who cares if it's passed by reference? Cuz altering it won't change any internal variables. But the bug is that a scalar is returned instead of a variable, which is easily fixed without removing return by ref.