• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get_instance now NULL in MY_Exceptions [CI 3.1.5]

#1
For years I've been extending the CI Exceptions class, specifically the show_404 method. I load my website template (a view), and then insert the error_404 view into it as a nested view. I'm just wondering what changed since 3.1.3 that would no longer allow me to use get_instance() the same way that I used to, because now I just get NULL, and that's no fun.


Code:
[b]Notice[/b]: Trying to get property of non-object in [b]/var/www/htdocs/houston/application/core/MY_Exceptions.php[/b] on line [b]49[/b]

An uncaught Exception was encountered
Type: Error
Message: Call to a member function set_status_header() on null
Filename: /var/www/htdocs/houston/application/core/MY_Exceptions.php
Line Number: 49
Backtrace:
File: /var/www/htdocs/houston/index.php
Line: 315
Function: require_once

As a work-around, I just used cURL to make a request to my custom error controller. Still would be nice to know what happened, and why get_instance now returns NULL, where it used to have the output and view methods. Is there a solution to this? Ideally, if I use get_instance, I'd get the loaded classes so I can use them.
Reply

#2
Crickets?
Reply

#3
There are no changes between 3.1.3 and 3.1.5 related to this.

You should be getting the same behavior in 3.1.3; it just depends on when you call get_instance(). Note that you're getting an instance of the controller, and with you doing this during 404 handling, that doesn't always happen under the same conditions.

When you call show_404() manually, that's most likely on a routed request that you chose to treat as a 404. But the same logic is also executed automatically when CI did NOT find a route, and thus did not instantiate a controller at all; i.e. there's no controller instance to be returned.
Reply

#4
Probably not the most elegant solution but we do a redirect to our error controller.

PHP Code:
<?php if ( !defined'BASEPATH' ) ) exit( 'No direct script access allowed' );

class 
MY_Exceptions extends CI_Exceptions {
    
/* public methods */

    
public function show_404$page ''$log_error true ) {
        
header'Location: https:/error/404' );

        exit;
    }
}

?>
Reply

#5
Well I feel pretty dumb. It was that I forgot to add a value to my 404_override route. Everything works fine now.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.