CodeIgniter Forums
get_instance problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: get_instance problem (/showthread.php?tid=27321)



get_instance problem - El Forum - 02-07-2010

[eluser]JCianflone[/eluser]
Hi everyone,
I'm trying to create a new Exceptions class for a little project I'm working on but I seem to have an issue with getting the CodeIgniter instance. The error I get is:

Quote:Fatal error: Call to undefined function get_instance() in ...

My code is this:

Code:
class HUB_Exceptions extends CI_Exceptions {
    
    private $CI;
    
    public function __construct() {
        parent::CI_Exceptions();
        
        $this->CI =& get_instance(); //It breaks on this line here...

    }
}

This is my first time extending a core class, so I'm not 100% sure what's breaking here.

Any help would be greatly appreciated.

Thanks!


get_instance problem - El Forum - 02-07-2010

[eluser]JoostV[/eluser]
You are extending the core. I think you can dirtectly refer to the CI superobject as $this.


get_instance problem - El Forum - 02-07-2010

[eluser]JCianflone[/eluser]
Doesn't look like I can, I tried this:

Code:
$this->session->set_item('error_heading', $heading);

and got another error:

Quote:Fatal error: Call to a member function set_item() on a non-object in...



get_instance problem - El Forum - 02-07-2010

[eluser]Shay Falador[/eluser]
Well, JoostV you are wrong, CI_Exceptions does not use the $this as we use it in controllers.

JCianflone, I guess the problem is that the Exceptions library is loaded BEFORE the base class is loaded and even it's filed loaded.
Therefor it doesn't exist yet..


get_instance problem - El Forum - 02-07-2010

[eluser]JCianflone[/eluser]
Yea, that's what I was thinking.

OK, well, lets see if I can do this same thing with hooks!


get_instance problem - El Forum - 02-07-2010

[eluser]JoostV[/eluser]
@shay You're right, did not read the question well.