php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: augusteiner at hotmail dot com
New email:
PHP Version: OS:

 

 [2010-08-19 23:48 UTC] augusteiner at hotmail dot com
Description:
------------
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-20 07:11 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-08-20 07:11 UTC] aharvey@php.net
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 
abstract?

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