June 11, 2008

Inherit abstract functions....

A error I find from time to time when I work with inheritance is this one:

Fatal error: Can’t inherit abstract function Cookie::setFlavor() (previously declared abstract in ChocolateCookie) in …

This happens when you try to define multiple abstract classes or interfaces with the same abstract functions - it’s right that this errors shows up, but today I stuck on this error for a while because I did not see the reason for that - so that’s a reminder for me ;)

And the tasty example to reproduce this error:

abstract class Cookie {
abstract public function setFlavor($flavor);

abstract class ChocolateCookie extends Cookie {
abstract public function setFlavor($flavor);

There are also some rejected bugreports about that :P #35057 #35832 #41145

© tolleiv 2016 - CC BY-SA 3.0 - Powered by Hugo