Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.