Admittedly my OOPHP is a little shaky but I can't see what's wrong with this. In one of my controllers I'm including a utils sheet which, like the controller, extends the base CI_Controller
class. This throws the fatal error:
Fatal error: Cannot redeclare class Utils in {file path}\utils.php on line 88
Controller:
class Dashboard extends CI_Controller {
public function __construct() {
//call parent constructor
parent::__construct();
//load utils
require 'application/helpers/utils.php'; //<-- utils loaded
$this->utils = new Utils(); //<-- utils instantiated
//load Dashboard model
$this->utils->load->model('dashboard');
}
//etc...
}
utils.php:
class Utils extends CI_Controller {
//prep for forms (on join or login views)
public function prep_form() {
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<li>', '</li>');
}
//etc - more util methods
}
Why does it think I'm RE-declaring Utils
despite calling it and instantiating it only once? Weird thing is, I have another controller, for another part of the site, with this same pattern and it has no complaints.
Finally, I tried moving the require
instruction outside the controller, and changing it to require_once
just in case something really was calling it twice, and in both cases the page just hangs, eventually resolving with no source code sent to the browser.
Thanks in advance.