# Missing signature violation warnings suck.

- Thread: https://externals.io/message/36898
- Original archive: https://news-web.php.net/php.internals/36898
- Started by Derick Rethans on 2008-04-09T09:27:36+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #36898 — Derick Rethans — 2008-04-09T09:27:36+00:00

URL: https://externals.io/message/36898#36898

Hello there,

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 = '' );
}

interface ezcSearchFindQuery extends ezcSearchQuery
{
}

class ezcSearchFindQuerySolr implements ezcSearchFindQuery
{
    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:

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 
it and it bails out on me. We can't have this. We need *warnings* 
(actually, it should be E_FATAL) for those cases in order to avoid 
problems. I don't know who removed this check, but please put it back 
in!

regards,
Derick


-- 
Derick Rethans
http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org

---

## #36902 — Felipe Pena — 2008-04-09T12:46:16+00:00

URL: https://externals.io/message/36898#36902 · In reply to: #36898

Em Qua, 2008-04-09 às 11:27 +0200, Derick Rethans escreveu:
> I don't know who removed this check, but please put it back 
> in!
> 

Hi Derick, 
it looks has been introduced by this patch suggested and discussed in
that thread:
http://marc.info/?l=php-internals&m=120430609612237&w=2

-- 
Regards,
Felipe Pena.

---

## #36903 — Christian Schneider — 2008-04-09T13:21:03+00:00

URL: https://externals.io/message/36898#36903 · In reply to: #36898

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

---

## #36907 — Stanislav Malyshev — 2008-04-09T16:40:19+00:00

URL: https://externals.io/message/36898#36907 · In reply to: #36898

Hi!

>     public function limit( $limit, $offset = '' );
>     public function limit( $limit = 10, $offset = 0 )
> 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:
> 
> Fatal error: Declaration of ezcSearchFindQuerySolr::limit() must be 
> compatible with that of ezcSearchQuery::limit() in /tmp/tmp/index.php on 
> line 11

Why it's correct? limit() with default can extend limit without default, 
since every place you could call ezcSearchFindQuery::limit you also 
could call ezcSearchFindQuerySolr::limit. No precondition is 
strengthened, so I don't see a problem there.

-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com
