Error Message "Strict Standards: Only Variables Should Be Passed by Reference"

PHP Strict Standards: Only variables should be passed by reference in .lib

This error happens because some functions not only return values but also (try to) change passed parameters (these params need to be passed by reference, because otherwise their value would be copied and there would be no effect outside function scope).

For example reset() returns first element, but also changes internal array pointer (current elemtent). If you pass an array not assigned to any variable (direct result of the function call) the pointer cannot be set, because this array in outer scope doesn't longer exist. To fix line 309 you need to split command into variable assignment and then pass it to reset function:

$event_list = event_list(array('artikul_id' => $event_artikul_ids), ' AND point_id > 0');
$event = reset($event_list);

Same error in line 87 (needs if with braces though).

The problem in line 155 is caused by html_rating_div_str() function. For some reason it also requires reference - its definition might look like:

function html_rating_div_str(&$array, $users_data, $string) {...}

...with & before one of the variables. The referenced parameter should be changed to variable first, and then passed to this function.

Strict Standards: Only variables should be passed by reference error

This should be OK

   $value = explode(".", $value);
$extension = strtolower(array_pop($value)); //Line 32
// the file name is before the last "."
$fileName = array_shift($value); //Line 34

PHP Strict Standards: Only variables should be passed by reference error

array_pop() takes an array as a reference and you are passing the return of a function which can't be referenced. See Passing By Reference.

Simply change to:

$array = Article::listAll(new DBEListCriteria(implode(' and ', $conditions), null, new DBEListOffset(1)));
return array_pop($array);

But I would ask, why not sort ORDER BY the rows in the query and LIMIT to 1?

Strict Standards: Only variables should be passed by reference [5.6]

Read the PHP doc of end:

The array. This array is passed by reference because it is modified by the function. This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference.

Which means you cannot pass explode function directly to end. Instead you need to do in two steps:

$var = explode('-', $url);
$numero = end($var);

end(explode) Strict Standards: Only variables should be passed by reference in

Why not use pathinfo (PHP >= 4.0.3), i.e.:

$ext = pathinfo($_FILES["rfile"]["name"])['extension'];

Live PHP demo

http://ideone.com/eMpbnL

Strict Standards: Only variables should be passed by reference

You can try this code:

<?php

<?php

function scanDirectoryImages($directory, array $exts = array('jpeg', 'jpg', 'png'))
{
if (substr($directory, -1) == 'uploads/') {
$directory = substr($directory, 0, -1);
}
$html = '';
if (
is_readable($directory)
&& (file_exists($directory) || is_dir($directory))
) {
$directoryList = opendir($directory);
while($file = readdir($directoryList)) {
if ($file != '.' && $file != '..') {
$path = $directory . '/' . $file;
if (is_readable($path)) {
if (is_dir($path)) {
return scanDirectoryImages($path, $exts);
}

$path_info = pathinfo($path);
$ext = strtolower($path_info['extension']);

if (is_file($path) && in_array($ext, $exts)) {
$html .= '<a href="' . $path . '"><img src="' . $path
. '" style="max-height:100px;max-width:100px" /></a>';
}
}
}
}
closedir($directoryList);
}
return $html;
}


Related Topics



Leave a reply



Submit