Jump to content

Only variables should be passed by reference


AdRock
Go to solution Solved by Ch0cu3r,

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);
    }
Link to comment
Share on other sites

  • Solution

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;
Edited by Ch0cu3r
Link to comment
Share on other sites

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.