Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter php7 errors

I've got a site on Codeigniter 2 and when I switch server's version to PHP7 I get the following two errors:

A PHP Error was encountered Severity: Notice Message: Only variables should be assigned by reference Filename: core/Controller.php Line Number: 51

$this->load->_base_classes =& is_loaded();

A PHP Error was encountered Severity: 8192 Message: Methods with the same name as their class will not be constructors in a future version of PHP; CI_DB_driver has a deprecated constructor Filename: database/DB_driver.php Line Number: 31

Does anyone know how to fix them?

like image 574
mmatti Avatar asked Dec 13 '15 10:12

mmatti


2 Answers

Eventually I just updated CI core to CodeIgniter 2.2.6. Had to change DB driver to mysqli (since mysql is no longer supported in php7) and re-added the ci_sessions table in database (no idea why). And works like a charm!

like image 150
mmatti Avatar answered Oct 22 '22 12:10

mmatti


Only variables should be assigned by reference

This error isn't PHP 7-exclusive, you'd get it in older versions too. Anyway, I think the issue here is in is_loaded() and it is not returning a reference properly. Does it return by-reference (is it like function &is_loaded())? If not, it needs to. Does it return a variable or an expression? If it's not a variable, you need to put it in one before you can return a reference to it.

PHP manual page for this error: http://php.net/manual/en/language.references.return.php

Methods with the same name as their class will not be constructors in a future version of PHP; CI_DB_driver has a deprecated constructor

In PHP 4, you made a constructor method by naming it the same as the class. So if your class was class FooBar, your constructor would be public function FooBar. In PHP 5 and beyond, though, the recommended name for a constructor is __construct. So, go and edit that class and rename its constructor to get rid of the deprecation errors. Be sure to look at any extending classes to see if they call that constructor method, too, so you can change them.

See the upgrading guide: http://php.net/manual/en/migration70.deprecated.php

Also see the RFC: https://wiki.php.net/rfc/remove_php4_constructors

like image 42
Andrea Avatar answered Oct 22 '22 12:10

Andrea