I’ve just upgraded my servers to PHP 5.4 and got this error when loading a project.
Declaration of MyModelName::beforeSave() should be compatible with Model::beforeSave( $options = array() )
There seems to be a problem when using PHP 5.4 and CakePHP 2.1 which results in this error. Since PHP 5.4 E_ALL
and E_STRICT are now combined and with a default CakePHP installation error reporting is set to E_ALL & ~E_DEPRECATED!
Luckily it is really easy to fix!
Fix 1:
Like most times in programming … read the friggin error message 🙂
As you are told … add the argument which is required in the function callback its signature:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// Old code public function beforeSave( ) { // Awesome code return true; } // New code public function beforeSave( $options = array() ) { // Awesome code return true; } |
Fix 2:
Configure the error handler configuration key in your core.php file to
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// Old version Configure::write('Error', array( 'handler' => 'ErrorHandler::handleError', 'level' => E_ALL & ~E_DEPRECATED, 'trace' => true )); // New version Configure::write('Error', array( 'handler' => 'ErrorHandler::handleError', 'level' => E_ALL & ~E_NOTICE & ~E_STRICT, 'trace' => true )); |