Declaration of SearchableBehavior::beforeSave() should be compatible with ModelBehavior::beforeSave(Model $model, $options = Array)

StackOverflow https://stackoverflow.com/questions/23448903

Question

I am using Searchable-Behaviour-for-CakePHP

The plugin eject error:

Strict (2048): Declaration of SearchableBehavior::beforeSave() should be compatible with ModelBehavior::beforeSave(Model $model, $options = Array) [APP/Plugin/Searchable/Model/Behavior/SearchableBehavior.php, line 5]

Strict (2048): Declaration of SearchableBehavior::afterSave() should be compatible with ModelBehavior::afterSave(Model $model, $created, $options = Array) [APP/Plugin/Searchable/Model/Behavior/SearchableBehavior.php, line 5]

The line 5 into SearchableBehavior.php is:

class SearchableBehavior extends ModelBehavior { // Line 5
public $__defaultSettings = array(
    'foreignKey' => false,
    '_index' => false,
    'rebuildOnUpdate' => true,
    'fields' => '*',
    'stopwords_lang' => 'es'
);

Any idea?

Was it helpful?

Solution

Change the method signature

Probably that plugin was created for an earlier version of CakePHP. The error reads:

Strict (2048): Declaration of SearchableBehavior::beforeSave() should be compatible with ModelBehavior::beforeSave(Model $model, $options = Array) [APP/Plugin/Searchable/Model/Behavior/SearchableBehavior.php, line 5]

I.e. in the searchable behavior there is this:

public function beforeSave(Model $Model) {

And instead it should be changed to

public function beforeSave(Model $model, $options = Array) {

That kind of warning will always be shown whenever a child class redefines a method and give s it a different signature.

OTHER TIPS

Should be

public function beforeSave(Model $model, $options = Array()) {
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top