Fix CodeIgniter 3 HMVC Error Running on PHP 7
CodeIgniter 3 HMVC is a great modular CI for developing web applications. However, if you’re running it on PHP 7, you may run into an error. In this post, we’ll show you how to fix the CodeIgniter 3 HMVC error running on PHP 7.
If you’re deploying a CodeIgniter 3 HMVC application to a server with PHP running, you may encounter an error about string. This is due to the fact that in PHP 7, the functionality of the strpos() function has changed.
Previously, needles that were not strung would be interpreted as strings, but in the new version of PHP, they will be treated as integers. This means that if you’re using CodeIgniter 3HMVC on a server with PHP 7 or higher, you will need to make sure that the needles you’re using are explicitly defined as strings. Otherwise, you may see errors like the one above.
A PHP Error was encountered Severity: 8192 Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior Filename: MX/Router.php
This error can be fixed by modifying a line in the MX/Router.php
file. Open the file at application\third_party\MX\Router.php
then replace
public function set_class($class) { $suffix = $this->config->item('controller_suffix'); if (strpos($class, $suffix) === FALSE) { $class .= $suffix; } parent::set_class($class); }
with
public function set_class($class) { $suffix = (string) $this->config->item('controller_suffix'); if ($suffix && strpos($class, $suffix) === FALSE) { $class .= $suffix; } parent::set_class($class); }