Bug #79925 [Com]: Magic method __set_state signature check does not support covariance
| From: | ondrej at mirtes dot cz | Date: | Mon, 03 Aug 2020 07:18:49 +0000 |
| Subject: | Bug #79925 [Com]: Magic method __set_state signature check does not support covariance | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228384@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
Comment by: ondrej at mirtes dot cz
Reported by: ondrej at mirtes dot cz
Summary: Magic method __set_state signature check does not
support covariance
Status: Verified
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:
*contravariance
Previous Comments:
------------------------------------------------------------------------
[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