Bug #78407 [Opn->Nab]: Contravariant Parameters bug

From: Date: Mon, 12 Aug 2019 19:01:26 +0000
Subject: Bug #78407 [Opn->Nab]: Contravariant Parameters bug
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222201@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78407&edit=1 ID: 78407 Updated by: nikic@php.net Reported by: damian dot jozwiak dot lodz at gmail dot com Summary: Contravariant Parameters bug -Status: Open +Status: Not a bug Type: Bug -Package: PHP Language Specification +Package: Scripting Engine problem Operating System: Ubuntu 18.04 PHP Version: 7.4.0beta2 Block user comment: N Private report: N New Comment: This is intentionally not allowed, because it is unsound. You can drop a parameter type, but you can't add one. Previous Comments: ------------------------------------------------------------------------ [2019-08-12 18:55:46] damian dot jozwiak dot lodz at gmail dot com Description: ------------ When class implement an interface it is not possible to override function parameter. The code works fine if base function is in class Test script: --------------- interface Test{ public function f1($param); } class inherited implements Test { public function f1(string $param):\DOMElement{ return new \DOMElement($param); } } $data = new inherited(); $node = $data->f1("node"); var_dump($node->nodeName); Expected result: ---------------- string(4) "node" Actual result: -------------- Fatal error: Declaration of inherited::f1(string $param): DOMElement must be compatible with Test::f1($param) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78407&edit=1

« previous php.bugs (#222201) next »