|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
23 + 35 = ?
Subscribe to this entry?

 [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 Apr 13 16:01:31 2024 UTC