Declaration of Class::save() should be compatible with that of Class::save()

I am extending the MongoCollection Class and I am getting this message.

Declaration of Db\Mongo\Collection::save() should be compatible with that of MongoCollection::save()

I understand that this is normally a pram declaration miss match.

Php.net says the prams are:

public mixed save ( array|object $a [, array $options = array() ] )

I have tried all the following to fix this problem:

public function save(array &$a, array $options = array())
public function save($a, array $options = array())
public function save(&$a, array $options = array())
public function save($a, $options = array())
public function save($a = array(), $options = array())

And many others and I can NOT seem to be able to match the type.

Does anyone have any ideas on how to fix this error? How do you declare a pram as array|object?

Answers


I got this error

Strict Standards: Declaration of MyMongoCollection::save() should be compatible with MongoCollection::save($array_of_fields_OR_object, array $options = NULL)

So I tried:

class MyMongoCollection extends MongoCollection {

    public function save($arr_obj, array $options= null) {

    }

}

and it works.


I wonder if you can get any information on the MongoCollection::save() method using the ReflectionClass:

$reflection = new ReflectionClass( 'MongoCollection' );

foreach ( $reflection->getMethod('save')->getParameters() as $param )
{ 
    var_dump( $param->getName(), $param->isArray(), $param->isOptional() ); 
}

to get the missing pieces, in the case the documentation is not up to date?

ps: this is a slightly modified code example taken from this ticket.

It looks like there are similar problems extending update method of the MongoGridFS extension of the MongoCollection class:

Issue with overriding MongoCollection::update


Need Your Help

Closing all pipes of a process

shell pipe c++ fork

I am working on making a program that will act in a similar way as a shell, but supports only foreground processes and pipes. I have multiple processes writing to the same pipe and some other prope...

Conditional expression in JSP with Struts2 tag

jsp struts2 struts-tags

I maintain an old application developed with Struts2.