|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #78325 Function overloading type prevents overloading
Submitted: 2019-07-23 08:26 UTC Modified: 2019-07-23 08:33 UTC
From: dallas at ekkysoftware dot com Assigned: cmb (profile)
Status: Not a bug Package: Class/Object related
PHP Version: 7.1.30 OS: Both
Private report: No CVE-ID: None
 [2019-07-23 08:26 UTC] dallas at ekkysoftware dot com
Issues with overriding parameters of the same function with different types is causing a compilation errors that I don't know how to fix.

If there is a fix, can you please let me know and put it somewhere on the Internet so Google and I can find it.

Test script:
class Fie{
protected $value;

function copy(Fie $new) : Fie
$this->value = $new->value;
return $this;

class Foh extends Fie{
protected $field;

function copy(Foh $new) : Foh
$this->field = $new->field;
return parent::copy($new);

Expected result:
Not needing to totally rewrite Fie's code in Foh.

$n = new Foh();
$b = new Foh();

Actual result:
PHP Fatal error:  Declaration of Foh::copy(Foh $new): Foh must be compatible with Fie::copy(Fie $new): Fie in test_file.php on line 29

Fatal error: Declaration of Foh::copy(Foh $new): Foh must be compatible with Fie
::copy(Fie $new): Fie in test_file.php on line 29


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-23 08:31 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2019-07-23 08:31 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

You're trying to use covariant method signatures here, which
violates the Liskov Substitution Principle, and is therefore not
allowed in PHP.
 [2019-07-23 08:33 UTC]
The return type change is allowed in PHP 7.4 (the parameter type change is not, as it is unsound).
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 22:01:31 2024 UTC