Bug #79925 [Ver->Csd]: Magic method __set_state signature check does not support covariance

From: Date: Mon, 03 Aug 2020 08:35:43 +0000
Subject: Bug #79925 [Ver->Csd]: Magic method __set_state signature check does not support covariance
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228387@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79925&edit=1 ID: 79925 Updated by: nikic@php.net Reported by: ondrej at mirtes dot cz Summary: Magic method __set_state signature check does not support covariance -Status: Verified +Status: Closed Type: Bug Package: Class/Object related Operating System: All PHP Version: 8.0Git-2020-08-02 (Git) Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikita.ppv@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=bb8b95be636528ebfc6f00b2153254d06e27ead9 Log: Fix bug #79925 Previous Comments: ------------------------------------------------------------------------ [2020-08-03 07:18:49] ondrej at mirtes dot cz *contravariance ------------------------------------------------------------------------ [2020-08-03 07:16:31] ondrej at mirtes dot cz Looks like the parameter types should also be given some care, I tried to see if they support covariance and so far it looks like they're not enforced at all: public static function __set_state(int $properties): object leads to no error on 3v4l. This also doesn't but I expect that: public static function __set_state(mixed $properties): object ------------------------------------------------------------------------ [2020-08-02 21:35:54] ondrej at mirtes dot cz Description: ------------ Magic methods from this RFC https://wiki.php.net/rfc/magic-methods-signature should support covariance but don't. You should be able to narrow down a return type but currently can't. Test script: --------------- <?php class Foo { /** * @param mixed[] $properties * @return Type */ public static function __set_state(array $properties): self { return new self(); } } Expected result: ---------------- nothing Actual result: -------------- Fatal error: Foo::__set_state(): Return type must be object when declared in... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79925&edit=1

« previous php.bugs (#228387) next »