Doc #79484 [Nab]: Declared full covariance and contravariance support should be refined

From: Date: Fri, 17 Apr 2020 14:07:17 +0000
Subject: Doc #79484 [Nab]: Declared full covariance and contravariance support should be refined
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17499@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79484&edit=1 ID: 79484 Updated by: derick@php.net Reported by: vlad dot turchinskiy at yandex dot ru Summary: Declared full covariance and contravariance support should be refined Status: Not a bug Type: Documentation Problem Package: *General Issues Operating System: any PHP Version: 7.4.5 Block user comment: N Private report: N New Comment: FWIW, I removed that category from the bug tracker now. Previous Comments: ------------------------------------------------------------------------ [2020-04-17 09:32:04] nikic@php.net What kind of variance is supported for arguments and return values is dictated by the Liskov substitution principle. "Full" support here just means that variance respects all subtyping relationships, as supposed to only some of them, as was the case in earlier PHP versions. Just to make this 100% clear: There will never be support for covariant argument types in PHP, because is simply is not sound. ------------------------------------------------------------------------ [2020-04-17 09:17:06] vlad dot turchinskiy at yandex dot ru cmb@php.net, > The PHP manual is already clear about that I'm sorry for being annoying, but it isn't. 1) "full covariance and contravariance support" for me means that i can use both in return types and function parameter types. I can't, because of (2) 2) "Function arguments are contra-variant, not co-variant" 3) "contravariance allows a parameter type to be less specific in a child method, than that of its parent." is ok, but what about covariance in parameter type? Nothing. Declared "full support" (1) becomes "partial" without any notice. It is not clear from docs that "Function arguments are contra-variant, not co-variant". This produces "what?!why?!" effect in situations like in test script (https://3v4l.org/vC0WM). ------------------------------------------------------------------------ [2020-04-17 09:00:15] vlad dot turchinskiy at yandex dot ru Fixed category ------------------------------------------------------------------------ [2020-04-17 08:57:56] nikic@php.net Can someone please remove the "PHP Language Specification" category on this bug tracker? php-langspec bug tracker is at https://github.com/php/php-langspec. ------------------------------------------------------------------------ [2020-04-17 08:53:03] cmb@php.net The PHP manual is already clear about that[1]: | Covariance allows a child's method to return a more specific | type than the return type of its parent's method. Whereas, | contravariance allows a parameter type to be less specific in a | child method, than that of its parent. It appears, though, that the language specification is not[2]. [1] <https://www.php.net/manual/en/language.oop5.variance.php> [2] <https://github.com/php/php-langspec/tree/master/spec> ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=79484 -- Edit this bug report at https://bugs.php.net/bug.php?id=79484&edit=1

« previous php.doc.bugs (#17499) next »