Bug #80487 [NEW]: PHP returns static when expecting self
| From: | raincomplain at outlook dot com | Date: | Sat, 05 Dec 2020 03:15:25 +0000 |
| Subject: | Bug #80487 [NEW]: PHP returns static when expecting self | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-230869@lists.php.net to get a copy of this message | ||
From: raincomplain at outlook dot com
Operating system: Irrelevant
PHP version: 8.0.0
Package: Class/Object related
Bug Type: Bug
Bug description:PHP returns static when expecting self
Description:
------------
PHP 8 throws a TypeError when expecting static but getting self, which
makes sense, but it seems to work the other way around! and PHP will not
complain when expecting self but getting static, this is not consistent
and can lead to unexpected result too.
Test script:
---------------
class A {
public static function get(): self {
return new static;
}
public static function name(): void {
echo 'A';
}
}
class B extends A {
public static function name(): void {
echo 'B';
}
}
B::get()::name();
echo $a->get()->name();
Expected result:
----------------
Fatal error: Uncaught TypeError: A::get(): Return value must be of type
A, B returned
Actual result:
--------------
B
--
Edit bug report at https://bugs.php.net/bug.php?id=80487&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80487&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80487&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80487&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80487&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80487&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80487&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80487&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80487&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80487&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80487&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80487&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80487&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80487&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80487&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80487&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80487&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80487&r=mysqlcfg