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?
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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With