|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-12-05 03:20 UTC] raincomplain at outlook dot com
[2020-12-05 03:25 UTC] levim@php.net
-Status: Open
+Status: Not a bug
[2020-12-05 03:25 UTC] levim@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 11:00:01 2025 UTC |
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