Derick Rethans wrote: > I've been working on some code, while developing on PHP 5.3. The code > resembles the following structure: > > <?php > interface ezcSearchQuery > { > public function limit( $limit, $offset = '' ); > } > > class ezcSearchFindQuerySolr implements ezcSearchQuery > { > public function limit( $limit = 10, $offset = 0 ) > { > $this->limit = $limit; > $this->offset = $offset; > } > } > ?> > > No problems at all while development, no warnings, no errors. Now when I > deployed this on a PHP 5.2 machine it bombed out, with the following > *correct* message:
I disagree, the error message with 5.2 was wrong IMHO, see below for reason. > Fatal error: Declaration of ezcSearchFindQuerySolr::limit() must be > compatible with that of ezcSearchQuery::limit() in /tmp/tmp/index.php on > line 11 > > And this really sucks. I made a mistake in my code (wrongly implemented > interface) and I get no warning (not even E_STRICT)... and then deploy Can you elaborate in how your implementation is wrong? ezcSearchFindQuerySolr accepts the same arguments ezcSearchQuery does so it is a valid implementation of the interface. Every user of the ezcSearchQuery interface can be given an instance of ezcSearchFindQuerySolr and it will work, so the http://en.wikipedia.org/wiki/Liskov_substitution_principle is fulfilled. This principle does not mean that all users of a specific implementation have to be able to be given another implementation of the interface and be happy with it. You can e.g. have class ezcOrderedSearchQuery implements ezcSearchQuery { public function limit( $limit, $offset = 0, $order = "ASC" ) { ... } } class ezcFilteredSearchQuery implements ezcSearchQuery { public function limit( $limit, $offset = 0 ) { ... } public function filter( $filter ) { } } ... which are in the same boat: ezcOrderedSearchQuery and ezcFilteredSearchQuery can be used as ezcSearchQuery but not necessarily the other way around. - Chris -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php