问题
I am currently moving a website over for a client. Their old host must be using an old version of PHP from what I can gather. The site is currently working on their current host. I am working to move this to a new host for them and I am getting the following error:
PHP Strict Standards: Only variables should be passed by reference in /home/parcelt2/core/public_html/loader.php on line 17
Below is a section of code with line 17 marked out
$uri = parse_url($_SERVER['REQUEST_URI']);
if (substr($uri['path'], -1, 1) == '/' && !sizeof($_POST)) {
$new_uri = substr($uri['path'], 0, -1);
if (strlen($new_uri) > 0) {
$page = reset(explode('/', $new_uri)); //line 17
if (!in_array($page, $exempt_requests)) {
if (isset($uri['query']) && strlen($uri['query']) > 0) {
$new_uri .= '?' . $uri['query'];
}
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $new_uri, true, 301);
exit;
}
}
}
Would anyone be able to provide a fix or some suggestion on how to fix this? I have tried reading other SO posts about this error but have found them hard to understand.
Thank you
回答1:
reset() takes a reference to an array (variable) so it will not work with the result of a function call.
You need to do something like this:
$arr = explode('/', $new_uri);
$page = reset($arr);
However, the array returned by explode()
will already have its internal pointer set to the first element. You shouldn't need to call reset at all.
来源:https://stackoverflow.com/questions/24438708/reset-strict-standards-only-variables-should-be-passed-by-reference