Search code examples
phpnoticee-notices

How to fix Notice: Only variable references should be returned by reference in


i am using php script got from torrenteditor to create torrent files , but when i create new torrent files, using specified method, torrent files gets created but i get lots of notices ., like this

Only variable references should be returned by reference in myfile.php on line 319

on this line

return new BEncode_End();

which is specified as another class as

class BEncode_End
{
    public function get_type()
    {
        return 'end';
    }
}

so how can i fix this notices ?

i am pretty new to classes , so dont know where to start.

complete script/code uploaded here http://pastebin.com/L6ktvrne , line 319

i am using

ini_set('display_errors', 1); 
error_reporting(E_ALL);

Solution

  • Based on the notice you get and on an answer to another related question:

    In PHP assignment expressions always return the assigned value. So $_config[0] =& $config returns $config - but not the variable itself, but a copy of its value. And returning a reference to a temporary value wouldn't be particularly useful (changing it wouldn't do anything).

    Changing your code from:

    return new BEncode_End();
    

    To:

    $cl = new BEncode_End();
    return $cl;
    

    Should solve your problem.