|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79754 Covariance fails with mixed type
Submitted: 2020-06-28 13:06 UTC Modified: 2020-06-28 13:32 UTC
From: raincomplain at outlook dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 8.0.0alpha1 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: raincomplain at outlook dot com
New email:
PHP Version: OS:


 [2020-06-28 13:06 UTC] raincomplain at outlook dot com
Since mixed type indicates the absence of a type then one would assume that omitting a return type in a child class's method that returns mixed type in a parent class is fine! but PHP refuses to compile

Test script:
class Foo {
    function fun(): mixed {
        return 33;

class Bar extends Foo {
    function fun() {
        return 33;

Expected result:
The expected is to compile with no error

Actual result:
Fatal error: Declaration of Bar::fun() must be compatible with Foo::fun(): mixed


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-28 13:32 UTC]
-Status: Open +Status: Not a bug
 [2020-06-28 13:32 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is expected behaviour. If a return type is missing, it is the implicit union of "mixed|void". As "mixed|void" is a wider type than just "mixed", allowing it would break LSP.

This is also explained in the RFC:
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 22 21:01:29 2024 UTC