What does this warning mean?

I got a strange error I am a little confused over

Strict Standards: Only variables should be passed by reference in /hermes/walnaweb10a/b2054/moo.teamluke/svr/my_property_detail.php on line 155 Strict Standards: Only variables should be passed by reference in /hermes/walnaweb10a/b2054/moo.teamluke/svr/my_property_detail.php on line 155 Strict Standards: Only variables should be passed by reference in /hermes/walnaweb10a/b2054/moo.teamluke/svr/my_property_detail.php on line 155 

Here is the foreach loop it seems to be complaining about

    foreach ($dir_contents as $file) {
        $file_type = strtolower(end(explode('.', $file)));

        if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) {
            echo '<img src="', $dir, '/', $file, '" alt="', $file, '" class="img-responsive img-thumbnail" width="100px"/>';
        }
}

The complaint is about the strtolower() function but don’t know how to pass a reference to the variable.

Hi @lurtnowski, what this means is that some functions expect a reference to a variable as a parameter, not a function call:

someFunction(&$variable) {
// The above $variable is a reference, which means that if you change its value the original variable will change too
}

When you are passing a function call as a parameter into a function that expects a reference you will get that warning.
The way to solve it is to assign variables to the function calls and pass the variables instead:

$var1 = explode('.', $file);
$var2 = end($var1);
$file_type = strtolower($var2);

Hope that helps…

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.