php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77507 No fatal error when implementing interface method with parameter type declared
Submitted: 2019-01-23 10:37 UTC Modified: 2019-01-23 11:22 UTC
From: a dot owrew at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.2.14 OS: Linux
Private report: No CVE-ID: None
 [2019-01-23 10:37 UTC] 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)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-23 11:22 UTC] cmb@php.net
-Status: Open +Status: Closed -Package: PHP Language Specification +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2019-01-23 11:22 UTC] 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 11:26 UTC] spam2 at rhsoft dot net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 20:01:31 2024 UTC