heron
heron

Reputation: 3661

Strange PHP issue

My function looks like that

protected function make_js_link($list, $folder, $parentdir = "js") {
        $links = array();

        $list = explode(',', $list);

        foreach ($list as $name) {
            $dir = $parentdir . "/";
            if (is_string($folder))
                echo $folder . "/";
            $links[] = '<script src="' . $dir . trim($name) . '.js"></script>' . "\n";
        }

        echo implode(" ", $links);
    }

So when js file located in $parentdir I'm calling like that

            $this->make_js_link('ckeditor', 0, 'incl/editor');

If file located in parentdir/another_dir, then calling like that

            $this->make_js_link('jquery', 'adapters', 'incl/editor');

The problem is, PHP escapes this part in both cases: even if I have folder variable with exact string value:

        if (is_string($folder))
            echo $folder . "/";

Where I did wrong?

Upvotes: 1

Views: 53

Answers (1)

Ramil Amerzyanov
Ramil Amerzyanov

Reputation: 1291

You did echo instead of

$dir = $parentdir . "/";
if (is_string($folder))
   $dir.= $folder . "/";

Upvotes: 3

Related Questions