Hack Forums
[PHP] Strict standards: Only variables should be passed by reference in - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] Strict standards: Only variables should be passed by reference in (/showthread.php?tid=5000741)



Strict standards: Only variables should be passed by reference in - Idolize - Sep 26, 2015

So this is the error I am getting basically.
[Image: zku7z8k.png]


Here is the code:
PHP Code

<?php
error_reporting
(E_STRICT);
$name = trim(strtolower($_GET['name']));


$name = str_replace(".", "\.", $name);
$name = str_replace("'", "\'", $name);
$name = str_replace("_", "\_", $name);

$log = array_pop(glob('logs/debug-*-*.log'));
$contents = file_get_contents($log);

if(
preg_match('/' . $name . '.*?-r(\d+\.\d+\.\d+\.\d+)/', $contents, $results))
{
        echo 
$results[1];
}
else
{
        
        if(
$error)
        {    
            echo 
'That user is not in our DB, please resovle them first!';
        }
}

?>

Basically, I have a folder full of logs, I want it to print out every IP that is connected with this username, but removing the duplicates and looking through all the .log files.


* - Yck - Sep 26, 2015

What is the $log, value or an array?
array_pop expects an array variable (by reference), not a value.


* - Novalty - Sep 26, 2015

Here is your problem...
PHP Code

<?php 
$log 
= array_pop(glob('logs/debug-*-*.log')); 

array_pop takes an argument that is passed by reference. That means you must give it a variable whereas you are just passing in an array which is returned from glob.

Changing it to the following should fix the issue:

PHP Code

<?php 
$filesArray 
= glob('logs/debug-*-*.log');
$log = array_pop($filesArray); 



* - Idolize - Sep 26, 2015

Now it wont print out anything :/


* - c00perzz - Sep 26, 2015

Either im confused, or :

a) there is no array to remove from
b) $log = array_pop(glob('logs/debug-*-*.log')); will end up in an empty array since its removing all log files.

Shouldnt it be like this? :

PHP Code

<?php 
$logs 
= glob('logs/debug-*-*.log');
foreach (
$logs as $log) {
$contents = file_get_contents($log);

if(
preg_match('/' . $name . '.*?-r(\d+\.\d+\.\d+\.\d+)/', $contents, $results))
{
        echo 
$results[1];
        
array_pop($log); // not even sure if this is needed
}
else
{
        
        if(
$error)
        {    
            echo 
'That user is not in our DB, please resovle them first!';
        }
}
}