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

The PHP warning Strict Standards: Only variables should be passed by reference will happen when a function requires a reference as arguments. The function uses that reference to change the internal representation of the arguments.
Lets try to produce this Strict Standards: Only variables should be passed by reference warning by considering multiple cases:

CASE 1:

echo array_pop(explode('.', '/data/filename.txt'));

Output

Strict Standards:  Only variables should be passed by reference

txt

Solution

$filenameArr = explode('.', '/data/filename.txt');
echo $file_extension = array_pop($filenameArr);

CASE 2:

shuffle(range(1, 100, 7));

Output

Strict Standards:  Only variables should be passed by reference

Solution

$sourceArr = range(1, 100, 7);
shuffle($sourceArr);

Comments