CodeIgniter 3 HMVC error running on PHP 7

When deploying a CodeIgniter 3 HMVC application to a server with PHP running, you will encounter an error about string.

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

You can fix this by modifying the file mentioned in the error message, MX/Router.php. The full file path is application\third_party\MX\Router.php.

This is the original code of set_class method:

public function set_class($class)
	{
		$suffix = $this->config->item('controller_suffix');
		if (strpos($class, $suffix) === FALSE)
		{
			$class .= $suffix;
		}
		parent::set_class($class);
	}

Replace it with

public function set_class($class)
	{
		/* $suffix = $this->config->item('controller_suffix');
		if (strpos($class, $suffix) === FALSE)
		{
			$class .= $suffix;
		} */
		$suffix = (string) $this->config->item('controller_suffix');
        if ($suffix && strpos($class, $suffix) === FALSE) {
            $class .= $suffix;
        }

		parent::set_class($class);
	}

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close