I don\'t understand what I\'m doing wrong...
abstract class Css {
abstract protected function parse($data);
}
abstract class CssElem extends Css {
a
You doesn't need to re-declare your abstract function again, declare just on implementation now.
When you extends Css on CssElem, the function parse come together. When you implement CssElem you should implement parse function too.
I recently encountered this Problem as well. For me it helped upgrading from PHP 5.3.8 to PHP 5.3.28.
I don't know exactly when the change happened but in 5.3.28 it is possible to redeclare interface methods in abstract classes and still inherit from them.
Try changing your intermediate class to:
abstract class CssElem extends Css {
// abstract protected function parse($data); // <-- take this away
}
See also this comment in the docs.
Quoting from the comment:
An abstract class that extends an abstract class can pass the buck to its child classes when it comes to implementing the abstract methods of its parent abstract class.
It seems however that this will be allowed in the next PHP version 7.2:
It is now allowed to override an abstract method with another abstract method in a child class. (https://wiki.php.net/rfc/allow-abstract-function-override)
Patrick Huy's answer was definitely helpful.
This bug is documented here:
https://bugs.php.net/bug.php?id=43200
As noted there, the bug is relevant if you want to extend legacy interfaces.
It can be reproduced on http://3v4l.org, showing that it is fixed since PHP 5.3.9.
This can be "fixed" with the solution by Matteo Tassinari, by commenting out the definition of foo() in the second interface.
http://3v4l.org/qo6sG
5.0.0 - 5.3.8: Fatal error: Can't inherit abstract function A::foo()
5.3.9 - *: No problem.
interface A {
function foo();
}
interface B extends A {
function foo();
}
http://3v4l.org/ZXq0O
5.0.0 - 5.3.8: Fatal error: Can't inherit abstract function A::foo()
5.3.9 - *: No problem.
interface A {
function foo();
}
interface B extends A {
function foo($x = NULL);
}
http://3v4l.org/5fPBO
5.0.0 - 5.3.8: Fatal error: Can't inherit abstract function A::foo()
5.3.9 - *: Fatal error: Declaration of B::foo() must be compatible with (that of) A::foo()
interface A {
function foo();
}
interface B extends A {
function foo($x);
}
(We are not surprised, this breaks in all PHP versions)
http://3v4l.org/UvcLA
5.0.0 - *: No problem
/**
* @legacy
*/
interface A {
function foo();
}
/**
* Supersedes legacy interface A
*/
interface B extends A {
/**
* @param int|null $x
* Optional parameter added in new version.
*/
# function foo($x = NULL);
}
class C implements B {
function foo($x = NULL) {}
}