Bug #73220 [Opn->Nab]: Classes implementing an interface can violate its method's signatures
| From: | rasmus@php.net | Date: | Sat, 01 Oct 2016 21:50:51 +0000 |
| Subject: | Bug #73220 [Opn->Nab]: Classes implementing an interface can violate its method's signatures | ||
| References: | 1 | Groups: | php.standards |
| Request: | Send a blank email to standards-+get-1131@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73220&edit=1
ID: 73220
Updated by: rasmus@php.net
Reported by: phansys at gmail dot com
Summary: Classes implementing an interface can violate its
method's signatures
-Status: Open
+Status: Not a bug
Type: Bug
Package: PHP Language Specification
Operating System: any
PHP Version: 7.0.11
Block user comment: N
Private report: N
New Comment:
Adding additional default values does not violate LSP (Liskov Substitution Principle) in that in
your example, B can be used in place of any other class that implements A and as such it is entirely
compatible with A and there should be no error.
Previous Comments:
------------------------------------------------------------------------
[2016-10-01 19:53:14] phansys at gmail dot com
Description:
------------
Classes implementing an interface can violate its method's signatures by adding more arguments
with a default value.
Test script:
---------------
interface A
{
public function test($one = null);
}
class B implements A
{
public function test($one = null, $two = null)
{
var_dump($one, $two);
}
}
Expected result:
----------------
Fatal error: Declaration of B::test($one, $two) must be compatible with A::test($one = NULL)
Actual result:
--------------
No error.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73220&edit=1