How do I fix the fatal error: unable to override class, only on Macintosh?

I only get this fatal error when running on a Macintosh, but not on a Windows browser, which doesn't make sense because, apart from checking the browser state, the conditional loops run the same code:

Can anyone help me figure out how to stop this error in php? The error occurs in the FIRST instance of QEnterKeyEvent ... and NOT the second. This makes no sense.

In the code, the first instance is the first time it's ever called, so the class hasn't been created yet as far as I can tell.

However, the error says: cannot override QEnterKeyEvent class

// Key-Specific Events (EnterKey, EscapeKey, UpArrowKey, DownArrowKey, etc.)

if (QApplication::IsBrowser(QBrowserType::Macintosh)) {
    echo "keyspecific events - macintosh";

    class QEnterKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 13';
    }
    class QEscapeKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 27';
    }
    class QUpArrowKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 38';
    }
    class QDownArrowKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 40';
    }
} else {
    echo "key specific events - windows";

    class QEnterKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 13';
    }
    class QEscapeKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 27';
    }
    class QUpArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 38';
    }
    class QDownArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 40';
    }
}

      

+1


source to share


4 answers


I see this sample code from the QCodo codebase? If this is the case, you should probably report it on the Bugs and Issues forum . After looking there I see that there are already a couple of reports: this and this ...

Here's the complete block of code (from a forum post on the Qcodo site):

// Key-Specific Events (EnterKey, EscapeKey, UpArrowKey, DownArrowKey, etc.)

if (QApplication::IsBrowser(QBrowserType::Macintosh)) {
    class QEnterKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 13';
    }
    class QEscapeKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 27';
    }
    class QUpArrowKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 38';
    }
    class QDownArrowKeyEvent extends QKeyPressEvent {
        protected $strCondition = 'event.keyCode == 40';
    }
} else {
    class QEnterKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 13';
    }
    class QEscapeKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 27';
    }
    class QUpArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 38';
    }
    class QDownArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 40';
    }
} 

      

So on a second reading, I believe that the problem is not that this block of code ends up in both class definitions, but that this block of code is actually being called twice. And it looks (at first glance at Qcodo) what it would do if Qcodo is initialized twice.



QApplicationBase :: Initialize () has the following code:

  // Preload Class Files
  foreach (QApplication::$PreloadedClassFile as $strClassFile)
      require($strClassFile);

      

Try replacing this with the code below and see if the problem is resolved. If so, you may have accidentally initialized Qcodo somewhere in your code.

  // Preload Class Files
  foreach (QApplication::$PreloadedClassFile as $strClassFile)
      require_once($strClassFile);

      

+1


source


Both blocks of code define the same class:

class QEnterKeyEvent extends QKeyDownEvent {
            protected $strCondition = 'event.keyCode == 13';
}

      

From the example code you give, it makes sense to define this class outside of the if / else statements entirely, which will reduce the amount of code to maintain and eliminate your error.

However, I suspect that you may not match the curly braces when reading the code; from the snippet, when inserting it, the error should not occur.

If the definition of the second class happens the same way as the first (since they are not part of the same conditional expression), then you would expect to see this error.



If you choose not to refactor your code to avoid duplication (you may have good reasons for the current structure, those not listed in the provided snippet), you can use PHP class_exists () to avoid trying to duplicate the class definition:

} else {
  if ( !class_exists('QEnterKeyEvent') ) {
    class QEnterKeyEvent extends QKeyDownEvent {
      protected $strCondition = 'event.keyCode == 13';
    }
  }
}

      

If you are using this approach, it makes sense to carefully check that the class is defined as you would expect it in all cases.

PS. Is this sample code from the QCodo codebase? If so, you should probably report it on your Bugs and Issues forum .

PPS. Oh look. See this and this ...

0


source


I ran into this issue while trying to install XSilva Lightspeed Webstore for a client. After some digging and testing, I think I have solved the problem. (FYI just changes "require" to "require_once" - although a good idea - doesn't work for me.) I know this is an ugly hack, but I wrapped the block of problematic code with a class_exists () check like this:

// Key-Specific Events (EnterKey, EscapeKey, UpArrowKey, DownArrowKey, etc.)
if (QApplication::IsBrowser(QBrowserType::Macintosh)) {
    if(!class_exists('QEnterKeyEvent') and !class_exists('QEscapeKeyEvent') and !class_exists('QUpArrowKeyEvent') and !class_exists('QDownArrowKeyEvent')) {
        class QEnterKeyEvent extends QKeyPressEvent {
            protected $strCondition = 'event.keyCode == 13';
        }   
        class QEscapeKeyEvent extends QKeyPressEvent {
            protected $strCondition = 'event.keyCode == 27';
        }   
        class QUpArrowKeyEvent extends QKeyPressEvent {
            protected $strCondition = 'event.keyCode == 38';
        }   
        class QDownArrowKeyEvent extends QKeyPressEvent {
            protected $strCondition = 'event.keyCode == 40';
        }   
    }   
} else {
    class QEnterKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 13';
    }   
    class QEscapeKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 27';
    }   
    class QUpArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 38';
    }   
    class QDownArrowKeyEvent extends QKeyDownEvent {
        protected $strCondition = 'event.keyCode == 40';
    }   
}   

      

0


source


There is a QCodo community branch called QCubed and they seem to have a fix in QA right now. http://trac.qcu.be/projects/qcubed/ticket/134

0


source







All Articles