Jump to content

Error: Only variables should be passed by reference


unemployment

Recommended Posts

I just enabled error handling on my server and got this error message:

 

Strict Standards: Only variables should be passed by reference in /var/www/mysite.com/mysite.com/assets/init.inc.php on line 17

 

But I'm not sure why this is happening because I'm not passing anything by reference to the page variable which is line 17.  Any thoughts?

 

<?php

$path = dirname(__FILE__);

ob_start();
session_start();

date_default_timezone_set("America/New_York");
setlocale(LC_MONETARY, 'en_US.UTF-8'); 

// include the necessary library files
foreach (glob($path . '/lib/*.inc.php') as $lib_file)
{
include($lib_file);
}

$page 				= substr(end(explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF'])), 0, -4);
$title 				= (array_key_exists($page, $page_names) !== false) ? $page_names[$page] : '';
$page_description 	        = (array_key_exists($page, $page_descriptions) !== false) ? $page_descriptions[$page] : '';

?>

But I'm not sure why this is happening because I'm not passing anything by reference to the page variable which is line 17.  Any thoughts?

$page 				= substr(end(explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF'])), 0, -4);

 

The end function accepts an array reference because it modifies the array's internal pointer as part of it's work.  By passing it the result of explode your not passing a reference value like it expects.  To remove the error you need to use a variable as the argument to end:

$page = explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF']);
$page = substr(end($page), 0, -4);

 

You'll also want to have a look at this snippet, to ensure that your PHP_SELF value actually contains what you expect it to.

 

Besides, basename () seems to be a better solution for what you're wanting to do. I recommend reading the PHP manual for more information on it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.