Search code examples
phpcodeigniter-2php-7php-7.3

Why does my PHP error controller work with PHP 5, but not PHP 7?


I'm migrating my project from PHP 5 to PHP 7.3, I have made the changes for the decrypted function with alternative functions. But am facing issue with the one controller file.

The same code works for PHP5 version, But when am trying to execute same code for PHP 7 it doesn't give any error even there is no error got added in errorLog file. Could you please help me out this.

I'm uploading my 'error.php' Controller file.

<?php
class Error extends CI_Controller {    
      private $controller = "error";      
      public function __construct() {
      parent::__construct();
      if ($this->phpsession->get('USERID')) {
          $headerContent['controller'] = $this->controller;
          $this->load->view('xome/header', $headerContent);
      } else {
          header("Location:" . ASITEURL . "/login/");
      }
    }

    public function index() {
      $this->load->view('x-404');
      $this->load->view('xome/footer');
    }

    public function permission() {
      $this->load->view('x-permission');
      $this->load->view('xome/footer');
    }

    public function display() {
      $this->load->view('x-error');
      $this->load->view('xome/footer');
    }
}
?>

When I hit the URL it should load the view page but unable to load any view file.

http://localhost/--project folder name--/error/permission

Even I checked there is no syntax error in the controller as well as any view file.


Solution

  • As of PHP7, Error is a reserved class name: http://php.net/manual/en/class.error.php.

    Change it to something else:

    class MyError extends CI_Controller 
    {
       // ....
    }