177

After the server PHP upgrade I am getting the following error with PHP Version 5.6.2 on Apache 2.0

A PHP Error was encountered
Severity: Notice
Message: Only variable references should be returned by reference
Filename: core/Common.php
Line Number: 257

How can I fix this?

Techie
  • 42,101
  • 38
  • 144
  • 232

3 Answers3

461

Edit filename: core/Common.php, line number: 257

Before

return $_config[0] =& $config; 

After

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

Update

Added by NikiC

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).

Update

This fix has been merged into CI 2.2.1 (https://github.com/bcit-ci/CodeIgniter/commit/69b02d0f0bc46e914bed1604cfbd9bf74286b2e3). It's better to upgrade rather than modifying core framework files.

mega6382
  • 8,624
  • 16
  • 43
  • 65
Techie
  • 42,101
  • 38
  • 144
  • 232
  • 2
    hiya... kind to explain why do this? it works and i don't know why :p – GuyFreakz Feb 12 '15 at 11:46
  • 4
    @GuyFreakz 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). – NikiC Feb 14 '15 at 10:42
  • yeah... that's good one! I have no idea why it could give that things out to be shown... :D – gumuruh Apr 09 '15 at 09:12
  • 4
    this has been merged in ci 2.2.1 `https://github.com/bcit-ci/CodeIgniter/commit/69b02d0f0bc46e914bed1604cfbd9bf74286b2e3`. It's better to upgrade like @Chad has mentioned. – Syakur Rahman Apr 23 '15 at 18:18
  • Nice. Work fine for me. – sugunan Dec 01 '15 at 10:27
  • 2
    I'm on an older version of codeigniter (2.0.2) when I try this fix on line 243 (that's where it shows up in my version) -- I get a php 500 error. Any idea how I can get this working? – JoeM05 Feb 15 '16 at 22:02
  • you are champss – devpro Mar 22 '17 at 14:53
  • Didnt work for me, hade do declare it to an another return value: $_config[0] =& $config; $returnValue = $_config[0]; return $returnValue; – DannyThunder Apr 12 '17 at 11:29
  • Just did this and i get a "HTTP ERROR 500" – deach Apr 04 '18 at 10:22
  • massive. I got in CI. Great Idea! – Deepak Keynes Sep 19 '18 at 15:04
8

this has been modified in codeigniter 2.2.1...usually not best practice to modify core files, I would always check for updates and 2.2.1 came out in Jan 2015

Chad
  • 81
  • 1
  • 1
1

It's not a better idea to override the core.common file of codeigniter. Because that's the more tested and system files....

I make a solution for this problem. In your ckeditor_helper.php file line- 65

if($k !== end (array_keys($data['config']))) {
       $return .= ",";
}

Change this to-->

 $segment = array_keys($data['config']);
    if($k !== end($segment)) {
           $return .= ",";
    }

I think this is the best solution and then your problem notice will dissappear.

Maniruzzaman Akash
  • 3,333
  • 1
  • 27
  • 28