php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34157 Abstract methods in interfaces break class-relations
Submitted: 2005-08-16 21:07 UTC Modified: 2005-08-16 22:05 UTC
From: jami dot pekkanen at ateco dot fi Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.4 OS: Linux
Private report: No CVE-ID: None
 [2005-08-16 21:07 UTC] jami dot pekkanen at ateco dot fi
Description:
------------
If interface contains abstract method, direct implementor isn't reported as subclass of the interface. However, if one has abstract class in the inheritance hierarchy, implementing classes are reported as subclasses of the interface.

Should abstract methods in interfaces even exist?

Reproduce code:
---------------
<?php
interface SomeInterface
{
	abstract public function Foo();
}

class BrokenImplementor implements SomeInterface
{
	public function Foo() {}
}

abstract class DummyParent implements SomeInterface {}
class WorkingImplementor extends DummyParent
{
	public function Foo() {}
}

var_dump(is_subclass_of('WorkingImplementor', 'SomeInterface'));
var_dump(is_subclass_of('BrokenImplementor', 'SomeInterface'));
?>

Expected result:
----------------
bool(true)
bool(true)

Actual result:
--------------
bool(true)
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-16 22:05 UTC] tony2001@php.net
Actually it has nothing to do with methods, abstract etc.

You get the result you get because 'BrokenImplementor' doesn't have parent classes at all, so it can't be a "subclass" of another class/interface.
But 'WorkingImplementor' is a subclass of class that implements the interface, so it works in this case.

Anyway, you should use 'instanceof' operator instead - it'd work in both cases, as it operates differently.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 12:01:29 2024 UTC