www.webdeveloper.com
Results 1 to 7 of 7

Thread: "Cannot override final method" when no override is made

  1. #1
    Join Date
    Aug 2007
    Location
    London
    Posts
    410

    "Cannot override final method" when no override is made

    Hi all,

    I have a class which extends my Controller class as follows:

    PHP Code:
    class ErrorsController extends Controller 
    If, and only if I set the configuration variable "maintenance" to on (which triggers a fabricated 515 error) I get the fatal error:

    Fatal error: Cannot override final method Controller::fireAction() in /Users/gid/Sites/bel/framework/controllers/ErrorsController.php on line 11
    Line 11 is the class declaration...
    If, however, another error is encountered, for example a 404 that fatal error does not occur.
    Nowhere in my declaration of the ErrorsController class is there an override for the fireAction() method.

    An ideas?
    Last edited by blue-eye-labs; 10-26-2009 at 12:38 PM. Reason: typo

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    Impossible to say without seeing the code, but I can only assume it as the message is saying - you define the method fireAction in your Controller class as final, and you are trying to also define a method fireAction in your ErrorController class. You really need to post the code though otherwise we only have the same error message as you to go on.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    I could not find anything in the bugs.php.net database, so either you've found a new bug, my searches were not on the right keywords, or your code is, in fact, trying to re-define that final method. Without any more information, I have no way of knowing which of those 3 options is correct (or a 4th one I've not thought of). (I suppose a 4th option is that the wrong error message is being displayed for some other error.)

    PS: If you want to post the actual code here, you might want to try to pare out as much code as possible and try to get it down the minimum amount of code needed to reproduce the error. That would serve 2 purposes: it might just show you where the problem is by limiting what you're looking at, and it will encourage the rest of us to spend time reading it. (I'm curious to find out what's going on, but I may not be curious enough to wade through a 1000 lines of code to find it. )
    Last edited by NogDog; 10-26-2009 at 07:21 PM.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Oct 2009
    Posts
    658
    Quote Originally Posted by NogDog View Post
    (I'm curious to find out what's going on, but I may not be curious enough to wade through a 1000 lines of code to find it. )
    Same
    Good Luck

    Santos Systems

  5. #5
    Join Date
    Aug 2007
    Location
    London
    Posts
    410
    @everyone

    Thanks for the responses. What's really weird about this is it doesn't happen every time ErrorsController is instantiated, but only with a specific error. I'll try and show loosely what is happening.

    In my Router class, the following occurs:
    PHP Code:
    public function loadController() {
        
    $_this =& Router::getInstance();
        
    $error 0;
        if(
    Config::read("maintenance") == "true") {
            
    $error 515;
        }
        
    $_this->_getController();
        if(!
    Core::loadSite("controller:" $_this->controller)) {
            
    Core::loadFramework("controller:" $_this->controller);
        }
        
        if(
    class_exists($_this->controller) && $error == 0) {
            
    $controller = new $_this->controller;
            
    Registry::write("controller"$controller);
            
    $action $_this->action;
            if(
    method_exists($controller$action)) {
                
    $args $_this->args;
                if(
    is_array($args)) {
                    
    array_unshift($args$action);
                } elseif(!
    is_null($args)) {
                    
    $args = array($action$args);
                } else {
                    
    $args $action;
                }
                
    call_user_func_array(array($controller"fireAction"), $args);
            } else {
                
    $_this->httpError(404);
            }
        } else {
            if(
    $error == 0) { $error 404; }
            
    $_this->httpError($error);
        }

    Which basically just calls the fireAction method of a specific controller. The line which reads if(Config::read("maintenance") == "true") { is where the maintenance status is checked and only when "maintenance" is "true" does the error occur. This causes a reroute via the httpError function which simply changes the route used to load the controller, loading the ErrorsController.

    For the sake of the amount you'll have to read, I won't post the whole of ErrorsController here because it's got a lot of code which simply defines the different error messages to use in different situations (to make it friendly).

    ErrorsController has the following method:
    PHP Code:
    function index($err) {
        if(!isset(
    $this->errors)) {
            
    $this->_initCodes();
        }
        if(
    array_key_exists($err$this->errors)) {
            
    header($err ": " $this->errors[$err], true$err);
            
    $title $this->errors[$err];
        } else {
            
    header($errtrue$err);
            
    $title "Error $err";
        }
        
    $this->set("url"$_SERVER["REQUEST_URI"]);
        
    $this->set("_TITLE"$title);
        
    $image = (in_array($err, array(403404))) ? $err "generic";
        
    $this->set("image"$image);
        
    $this->set("error"$err);
        
    $this->set("info"$this->_getErrorInfo($err));
    }

    private function 
    _initCodes() {
    // Simply gives short titles for each error code...
    }

    private function 
    _getErrorInfo($err) {
    // Gives longer more informative messages to the user.

    And that's it!

    This actually used to work not so long ago so I assume it must be a different error triggering this incorrect error.

  6. #6
    Join Date
    Nov 2008
    Posts
    2,477
    Can you post the Router::httpError() method please.

    EDIT: This may sound stupid but it's caught me out a few times before - are you 100% sure the correct ErrorsController.php is being loaded? Is it possible you have an older version somewhere which may actually define a fireAction method on line 11?
    Last edited by Mindzai; 10-27-2009 at 06:58 AM.

  7. #7
    Join Date
    Aug 2007
    Location
    London
    Posts
    410
    Router.php:

    PHP Code:
    public function httpError($err) {
        
    $route "/errors/index/" $err "/";
        
    Router::reroute($route);
    }

    public function 
    reroute($route) {
        
    $_this =& Router::getInstance();
        
    $_this->_clearRoutes();
        
    $_GET['route'] = $route;
        
    $_this->rerouted true;
        
    $_this->loadController();

    I'm fairly sure that it is ErrorsController which is being loaded because I tried commenting out the entire class and all that happened is I got a blank screen (and no errors).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles