unemployment Posted August 15, 2012 Share Posted August 15, 2012 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] : ''; ?> Quote Link to comment https://forums.phpfreaks.com/topic/267091-error-only-variables-should-be-passed-by-reference/ Share on other sites More sharing options...
kicken Posted August 15, 2012 Share Posted August 15, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/267091-error-only-variables-should-be-passed-by-reference/#findComment-1369493 Share on other sites More sharing options...
Christian F. Posted August 15, 2012 Share Posted August 15, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267091-error-only-variables-should-be-passed-by-reference/#findComment-1369574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.