php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72755 Signature mismatch during inheritance
Submitted: 2016-08-04 13:11 UTC Modified: 2016-08-05 08:33 UTC
From: pawzar at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.6.24 OS: Linux 4.4.0-31-generic
Private report: No CVE-ID: None
 [2016-08-04 13:11 UTC] pawzar at gmail dot com
Description:
------------
I am trying to adjst some code to E_STRICT standards but I am getting a "Signature mismatch during inheritance" error, when it seems that there sould be none.

What is more bizarre is that this error only occurs when I am trying to implement SomeInterface in the extendig class.

Test script:
---------------
interface SomeInterface
{
}

abstract class FooClass
{
}

abstract class FooBarClass extends FooClass
{
}

abstract class LightAbstract
{
    public function returnArgument(FooClass $arg)
    {
        return $arg;
    }
}

// OK
class RedLight extends LightAbstract
{
    public function returnArgument(FooBarClass $arg)
    {
        return parent::returnArgument($arg);
    }
}

// Outputs an error (E_STRICT)
class BlueLight extends LightAbstract implements SomeInterface
{
    public function returnArgument(FooBarClass $arg)
    {
        return parent::returnArgument($arg);
    }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-04 13:31 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-08-04 13:31 UTC] cmb@php.net
PHP does not support covariant parameter types. For now only
invariant parameter types are supported (i.e. the parameter types
of overriden methods must be identical to the inherited methods).
Sometime, contravariant parameter types might be supported, but
most likely never covariant parameter types, as these break the
Liskov substitution principle.
 [2016-08-05 07:53 UTC] pawzar at gmail dot com
The examle does not break the Liskov substitution principle.

Please note, that the only difference between RedLight and BlueLight classes is "implements SomeInterface". 

So where it the logic in that?
 [2016-08-05 08:33 UTC] cmb@php.net
*Both* method declarations will emit a strict notice (a warning in
PHP 7), see <https://3v4l.org/UrWkU>. And that is expected
behavior.

> The examle does not break the Liskov substitution principle.

It does, see
<https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)#Covariant_method_argument_type>
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 04:00:01 2026 UTC