Bug #72119 [Nab]: Interface declaration compatibility regression with default values
| From: | dmitry@php.net | Date: | Thu, 28 Apr 2016 16:34:15 +0000 |
| Subject: | Bug #72119 [Nab]: Interface declaration compatibility regression with default values | ||
| References: | 1 | Groups: | php.standards |
| Request: | Send a blank email to standards-+get-1084@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72119&edit=1
ID: 72119
Updated by: dmitry@php.net
Reported by: ben dot davies at gmail dot com
Summary: Interface declaration compatibility regression with
default values
Status: Not a bug
Type: Bug
Package: PHP Language Specification
PHP Version: 7.0.6
Assigned To: levim
Block user comment: N
Private report: N
New Comment:
The original problem was introduced by attempt to fix #71428 (that expects exactly the opposite
behavior) in commit ee9a78a033696ff9546fb1dbfecd28f20477b511
Previous Comments:
------------------------------------------------------------------------
[2016-04-28 15:26:30] ben dot davies at gmail dot com
Hi both,
No doubt you are both correct, but this appears to be a BC break.
This works in every version of php up to 7.0.6.
https://3v4l.org/VhEtd
Thanks
------------------------------------------------------------------------
[2016-04-28 15:23:48] levim@php.net
I have confirmed that this is not a bug. The reason is that in the interface you are permitted to
pass null:
<?php
$Foo->bar(null);
?>
However, in the implementing class Hello it would not be permitted. Everything permitted in the
parent must also be permitted in the child, thus it is not a bug.
------------------------------------------------------------------------
[2016-04-28 15:22:29] bwoebi@php.net
This is not a bug; your code is a LSP violation which had been fixed in bug #71428.
In the concrete example, the Foo::bar() function can be passed null, but Hello::bar() cannot.
[This is something we try to fix with nullable parameters/null unions in 7.1.]
------------------------------------------------------------------------
[2016-04-28 15:18:48] levim@php.net
This was changed in commit e9d65160 by Dmitry. It appears to be a fix for a different bug (71978).
------------------------------------------------------------------------
[2016-04-28 11:33:37] ben dot davies at gmail dot com
Description:
------------
I wanted to raise this against 7.0.6, but it was not available in the list above, despite being
released?
There seems to be a regression in interface method declaration compatibility checking.
The below test script only fails on 7.0.6.
It also only fails if the $baz is type hinted as array.
Test script:
---------------
<?php
interface Foo {
public function bar(array $baz = null);
}
class Hello implements Foo {
public function bar(array $baz = [])
{
}
}
Expected result:
----------------
N/A
Actual result:
--------------
Fatal error: Declaration of Hello::bar(array $baz = Array) must be compatible with Foo::bar(array
$baz = NULL) in /in/VhEtd on line 7
Process exited with code 255.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72119&edit=1