Codeigniter 2 with variable reference error in PHP version 5.6

Asked

Viewed 6,033 times

1

I am using version 2.1.3 of Codeigniter and when I open any page the following error is displayed:

PHP Error was encountered

Severity: Notice

Message: Only variable References should be returned by Reference

Filename: core/Common.php

Line Number: 257

On the line 257 has a strange code:

return $_config[0] =& $config;

This message has started to appear since I upgraded the PHP version to 5.6.

Why does this error occur? How can I resolve it?

  • 1

    Why the framework uses archaic techniques ...

  • @rray and now, who can defend us?

  • I just found this kkk line.

  • Tense is if I have to mess with the source code :\

  • 1

    is pq you have not seen the upload lib .... and yes it has touch the framework ...

  • 2

    @Wallacemaxters this was solved in 2.2.1 : https://github.com/bcit-ci/CodeIgniter/commit/69b02d0f0bc46e914bed1604cfbd9bf74286b2e3

  • Update the version... These things don’t happen anymore...

Show 2 more comments

1 answer

5


The Codeigniter framework has a great legacy, so it uses some techniques that have fallen out of use. The problem here is the & in the signature of the method get_config(), which requires the return to be a reference (variable).

If you can measure the impact of the change, another solution is to remove the & signature. As this piece of code is part (Comum/ Common ;) ) framework, may lead to unexpected behaviors.

Signing:

function &get_config($replace = array())

Change:

return $_config[0] =& $config;

To: as corrected in version 2.2.x

$_config[0] =& $config;
return $_config[0];

A simple way to reproduce the error is with the following code:

function &olaMundo(){
    return 'Ola mundo';
}

echo olaMundo(); //Notice: Only variable references should be returned by reference in 

Correction:

function &olaMundo(){
    $x = 'Ola mundo';
    return $x;
}

Functional example run in several versions of php.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.