This should be a pretty straightforward classes and interfaces question, but please bear with me while I lay out my example.
In the Propel ORM library, all the database tables are abstracted as classes called BaseTablename. Various methods for interacting with the database are defined in the base obect. Then the library also generates classes named after the tables, such as Tablename, which are super convenient for overriding the base methods and adding custom methods.
I'm just trying to override the default delete() method to be able to delete some dependent data. But when I declare the overriding method, I get the following error:
Fatal error: Declaration of Tablename::delete() must be compatible with that of Persistent::delete()
So, considering the following basic definitions, why is it that I cannot override the delete() method?
/**
* Part of the Propel library
*/
interface Persistent {
public function delete (PropelPDO $con = null);
}
/**
* Generated by Propel
*/
class BaseTablename extends BaseObject implements Persistent {
public function delete (PropelPDO $con = null) {
doesImportantStuff();
}
}
/**
* Skeleton class is generated by Propel
*/
class Tablename extends BaseTablename {
/**
* MY OWN BEAUTIFUL [BUT BROKEN] CODE
*/
public function delete (PropelPDO $con = null) {
doMyOwnStuff();
// Added this 2011-05-30 -- As it happens, this IS the Problem!
// I needed to add the $con parameter to the call to preserve
// the "chain of compatibility", so to speak.
parent::delete();
}
}
Update: I've added my parent::delete() call, which I failed to include in my original example code. It really would have made all the difference. Sorry folks, and thanks so much to those who confirmed the working code
The answer was that I needed to preserve the parameter on all declarations and calls. My overloaded function should have read:
public function delete (PropelPDO $con = null) {
doMyOwnStuff();
parent::delete($con);
}
This code works. Problem must be in server copy or PHP version. (I've run the tests over PHP Version 5.3.3-7+squeeze1 without problems)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With