Bug #77507 [Com]: No fatal error when implementing interface method with parameter type declared
| From: | spam2 at rhsoft dot net | Date: | Wed, 23 Jan 2019 11:26:09 +0000 |
| Subject: | Bug #77507 [Com]: No fatal error when implementing interface method with parameter type declared | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219151@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77507&edit=1
ID: 77507
Comment by: spam2 at rhsoft dot net
Reported by: a dot owrew at gmail dot com
Summary: No fatal error when implementing interface method
with parameter type declared
Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 7.2.14
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
if 7.0/7.1 would have worked as sane as 7.2 in that context it would have saved a lot of hours and
headache when we added type-hints to our complete codebase where you start to extend shared
libraries and every custom consumer was broken in one or the other direction and there are still too
much cases ending in fatal errors
Previous Comments:
------------------------------------------------------------------------
[2019-01-23 11:22:07] cmb@php.net
This is a deliberate change[1], mostly to accommodate libraries
which want to add paramter type hints without breaking existing
clients. It is also documented in the migration guide[2].
[1] <https://wiki.php.net/rfc/parameter-no-type-variance>
[2] <http://de2.php.net/manual/en/migration72.new-features.php#migration72.new-features.param-type-widening>
------------------------------------------------------------------------
[2019-01-23 10:37:42] a dot owrew at gmail dot com
Description:
------------
As it states in the summary, up until PHP 7.1.26, implementing an interface method without providing
the full signature would cause a fatal error. Starting PHP 7.2.0 it appears to be more lax. In the
example, the missing string parameter type is causing a fatal error prior to PHP 7.2.0.
Test script:
---------------
<?php
interface SomeInterface {
public function setSome(string $some);
}
class SomeClass implements SomeInterface {
public function setSome($some){}
}
Expected result:
----------------
Fatal error: Declaration of SomeClass::setSome($some) must be compatible with
SomeInterface::setSome(string $some)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77507&edit=1