Bug #76905 [Nab]: Scope variable resolution

From: Date: Wed, 19 Sep 2018 19:41:00 +0000
Subject: Bug #76905 [Nab]: Scope variable resolution
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217143@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76905&edit=1 ID: 76905 User updated by: rawsrc at gmail dot com Reported by: rawsrc at gmail dot com Summary: Scope variable resolution Status: Not a bug Type: Bug Package: *General Issues Operating System: Windows 7 PHP Version: 7.2.10 Block user comment: N Private report: N New Comment: Thanks for your quick answer :-) "That may change in the future." Great, i hope so. Previous Comments: ------------------------------------------------------------------------ [2018-09-19 17:59:26] requinix@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration > Note: > When overriding a parent method, the child's method must match any return type declaration > on the parent. If the > parent doesn't define a return type, then the child method may do so. Return types are currently invariant, meaning the type must exactly match the parent. That may change in the future. ------------------------------------------------------------------------ [2018-09-19 17:52:29] rawsrc at gmail dot com Description: ------------ Hi, Standard PHP 7.2.10 installation on Windows 7x64. Test script: --------------- <?php declare(strict_types=1); namespace ns1 { class abc { } }; namespace ns2 { interface interfaceXyz { public function getMe(): \ns1\abc; } }; namespace ns3 { class def extends \ns1\abc { function checkInstance() { return ($this instanceof \ns1\abc) ? '\ns3\def is an instance of \ns1\abc' : '\ns3\def is different of \ns1\abc'; } } echo (new def)->checkInstance(); // result = "\ns3\def is an instance of \ns1\abc" }; namespace ns4 { class ghi implements \ns2\interfaceXyz { public function getMe(): \ns3\def { // here : \ns3\def (derivated from \ns1\abc ) is an instance of \ns1\abc but is not compliant with the interface that expect an \ns1\abc instance !!! return 'hello world'; } } echo (new ghi)->getMe(); } Expected result: ---------------- Hello world Actual result: -------------- \ns3\def is an instance of \ns1\abc Fatal error: Declaration of ns4\ghi::getMe(): ns3\def must be compatible with ns2\interfaceXyz::getMe(): ns1\abc ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76905&edit=1

« previous php.bugs (#217143) next »