Unable to declare a child class method declared in the Super Class interface

This should be a fairly simple question of classes and interfaces, but please bear with me as I set out my example.

In the Propel ORM library, all database tables are abstracted as classes with a name BaseTablename. Various methods of interacting with the database are defined in the base area. The library then also generates classes named after the tables, such as Tablenamethose that are super convenient for overriding basic methods and adding custom methods.

I'm just trying to override the delete()default method to be able to delete some dependent data. But when I declare an overriding method, I get the following error:

Fatal error: Tablename :: delete () declaration must be compatible with Persistent :: delete () declaration

So, given the following basic definitions, why can't I override the method delete()?

/**
 * 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 added my call to parent :: delete (), which I could not include in my source code sample. That would really make a big difference. Sorry guys and many thanks to those who confirmed the working code.

The answer was that I needed to save the parameter in all announcements and calls. My overloaded function should be read:

    public function delete (PropelPDO $con = null) {
        doMyOwnStuff();

        parent::delete($con);
    }
+3
source share
2 answers

. PHP. ( PHP 5.3.3-7 + squeeze1)

+1

, . , -, . C, , , , , .

+1

All Articles