Charles Murray Charles Murray - 4 months ago 22
PHP Question

PHP5 with old PHP4 code

My friend wants me to tweak his website. But I'm getting the errors


Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\htdocs\toolmanager\toolmanager\index.php on line 7

Fatal error: Cannot re-assign auto-global variable _REQUEST in C:\xampp\htdocs\toolmanager\toolmanager\includes\classloader_platform.php on line 154


when I try to run the code on apache with PHP5. Here's the code:

require("includes/classloader_platform.php");
line 7->$classloader =& NEW classloader('0','30',$_GET,'1');
$classloader->initialize($classloader);

line 154-> function __construct($cache=false,$cache_lifecycle=false,$_REQUEST,$template_parser=false) {
ini_set("memory_limit","200M");
//globalize _REQUEST
$this->_REQUEST=$_REQUEST;
...


I think it's because he wrote it by PHP4 standards so would it be better to switch apache to PHP4 or are there some simple fixes for these errors?

Answer

Do not revert to PHP 4. It is old and unsupported.

For "Deprecated: Assigning the return value of new by reference", just remove the &. It's redundant.

$classloader = NEW classloader(...);

For "Fatal error: Cannot re-assign auto-global variable", rename the function argument $_REQUEST to something else such as $REQUEST, then rename the subsequent occurrences of it within the function. You can't have a function argument with the same name as a superglobal.

function __construct($cache=false,$cache_lifecycle=false,$REQUEST,$template_parser=false) {
    // ...
    $this->_REQUEST=$REQUEST;
    // ...
Comments