Jump to content

Only variables should be passed by reference


AdRock

Recommended Posts

I have this function that creates breadcrumbs from the URL

 

It appears to work but i get these error messages

 

Notice: Undefined index: HTTPS in C:\www\mvc\libs\Braveheart.php on line 13

Strict Standards: Only variables should be passed by reference in C:\www\mvc\libs\Braveheart.php on line 16

 

 

Line 13 points to

$base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';

and line 16 is

$last = end(array_keys($path));

Any ideas how i can remove these errors/warnings?

 

here is the code

public function breadcrumbs ($separator = ' » ', $home = 'Home') {
   
        $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
        $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
        $breadcrumbs = array("<a href=\"$base_url\">$home</a>");

        $last = end(array_keys($path));

        foreach ($path AS $x => $crumb) {
            $title = ucwords(str_replace(array('.php', '_'), Array('', ' '), $crumb));
            if ($x != $last){
                $breadcrumbs[] = '<a href="'.$base_url.'/'.$crumb.'">'.$title.'</a>';
            }else{
                $breadcrumbs[] = $title;
            }
        }

        return implode($separator, $breadcrumbs);
    }

First notice message can be solved by checking to see if the HTTPS server exists

$base_url = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';

Second error can solved with

$keys = array_keys($path);
$last = end($keys);

// OR just
$last = count($path) - 1;

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.