|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52648 interface/class
Submitted: 2010-08-19 23:48 UTC Modified: 2010-08-20 17:53 UTC
From: augusteiner at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: Irrelevant OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: augusteiner at hotmail dot com
New email:
PHP Version: OS:


 [2010-08-19 23:48 UTC] augusteiner at hotmail dot com
A class that implements an interface should implement interface's methods, but a method inside that class with type hint of class that implements the interface would be accepted. Or not!?

After all, both are hierarchically identical.

Test script:
interface IEntity
    public function equals(IEntity $other);

class Entity implements IEntity
    public function equals(Entity $other)
        return $this === $other;

Actual result:
Fatal error: Declaration of Entity::equals() must be compatible with that of IEntity::equals() in C:\wamp\www\horusweb\models\Coded.class.php


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-20 07:11 UTC]
-Status: Open +Status: Bogus
 [2010-08-20 07:11 UTC]
This is by design. In your example, Entity::equals() is more restrictive than IEntity::equals(): it wouldn't accept another class that implemented IEntity independently of Entity, even though the interface explicitly allows that.
 [2010-08-20 17:53 UTC] augusteiner at hotmail dot com
But if instead of an interface it was an abstract class with Equals marked as 

This situation could not be compatible with my first description!?
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Mar 02 01:01:28 2024 UTC