php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41145 Interface, Abstract Class & Methods
Submitted: 2007-04-20 08:00 UTC Modified: 2007-04-21 20:56 UTC
From: gerald at copix dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.1 OS: Linux
Private report: No CVE-ID: None
 [2007-04-20 08:00 UTC] gerald at copix dot org
Description:
------------
When we want to implement an interface in a child class that extends an abstract class that contains an abstract method that is in the interface, we get an error.

This kind of bug has already been submited in #35057 and was marked as bogus because AClasse::show obviously is not the same as IClasse::show.

But in the code we only say that IClasse::show is the same as AClasseConcrete::show.

To me, the IClasse should not care how AClasseConcrete manage to implements the interface. The important thing is that AClasseConcrete::show IS the same as IClasse::show.

I've checked the documentation and was not able to find this exact case and I've try this concept in other langages (like Java) with success.

I think at least it should be discussed.

If it has been discussed already, I'm really sorry for the time I made you spent on this.

Greatings

Reproduce code:
---------------
interface IClasse {
	public function show ();
}

abstract class AClasse  {
	abstract public function show (); 
}

class AClasseConcrete extends AClasse implements IClasse {
	public function show (){
		echo "Everything is ok";
	}
}

$classe = new AClasseConcrete ();
$classe->show (); 

Expected result:
----------------
"Everything is ok"

Actual result:
--------------
Fatal error: Can't inherit abstract function IClasse::show() (previously declared abstract in AClasse) in /home/geraldc/workspace/Copix_3/www/syntax_playground.php

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-21 20:56 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This kind of inhereitance trickery is only useful and working in languages that support MI and there you need to have the leave class reimplement the method or explicitly use one of the base class\' implementation regardless of whether you provide new code or not. This is the case because both the abstract class and the interface are two independant origins of the method. Thus they are considered different. What you can do instead is having a basic interface that only contains the shared method. Doing so is absolutely correct because as you say they are the same protocol entity. And if you were not able to ?rovide a shared base for them, than indeed the methods are different.
 [2012-02-02 22:02 UTC] lsmith@php.net
see #43200
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 26 18:01:33 2024 UTC