Req #80921 [NEW]: allow parameter type hints for poorly typed interface methods

From: Date: Tue, 30 Mar 2021 20:31:08 +0000
Subject: Req #80921 [NEW]: allow parameter type hints for poorly typed interface methods
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233076@lists.php.net to get a copy of this message
From: smiley at chillerlan dot net Operating system: PHP version: Irrelevant Package: Class/Object related Bug Type: Feature/Change Request Bug description:allow parameter type hints for poorly typed interface methods Description: ------------ Hello! I'd like to be able to add parameter type hints for poorly typed interface methods for type security and consistency. We're currently allowed to add return types in case they're not declared in the interface or omit existing type hints in the interface, but for some reason the aforementioned probably most important feature is missing. A userland example would be the dilemma of a PSR-7 update: https://github.com/php-fig/http-message/pull/83 I understand that this might require an RFC, but i don't possess neither the technical insight, nor the mental capacity to start such a process. Don't mind me if plans/feature request for such an update already exist. :) Test script: --------------- <?php // a poorly typed interface interface PoorlyTypedInterface{ public function methodWithoutTypeHints($string, $int); } // currently we're only allowed to add a return type class PoorlyTypedClass implements PoorlyTypedInterface{ public function methodWithoutTypeHints($string, $int):array{ return [$string, $int]; } } // proposal: allow adding parameter type hints class StronglyTypedClass implements PoorlyTypedInterface{ public function methodWithoutTypeHints(string $string, int $int):array{ return [$string, $int]; } } Actual result: -------------- Fatal error: Declaration of StronglyTypedClass::methodWithoutTypeHints(string $string, int $int): array must be compatible with PoorlyTypedInterface::methodWithoutTypeHints($string, $int) -- Edit bug report at https://bugs.php.net/bug.php?id=80921&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80921&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80921&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80921&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80921&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80921&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80921&r=support Expected behavior: https://bugs.php.net/fix.php?id=80921&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80921&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80921&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80921&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80921&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80921&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80921&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80921&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80921&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80921&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80921&r=mysqlcfg

« previous php.bugs (#233076) next »