Search code examples
cakephpbehaviorsearchable-plugin

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


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?


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.