-2

I am encountering the following warning:

Strict Standards: Declaration of FGLU_Activity::delete() should be compatible with FGLU_Entity::delete($id, $commit = true) in ...

FGLU_Activity extends FGLU_Entity and does NOT override the static ::delete method.

Any hints as to how to avoid this error the next time i encounter it?

<?php

class FGLU_Entity {

    /*
     * ...
     */


    static function delete($id,$commit=true) {

        global $wpdb;

        // first, delete any rows in mapped tables
        $total_count = 0;
        if ($commit) $wpdb->query("START TRANSACTION");

        $instance = new static::$class_name();
        $instance->{static::$key} = $id;

        /*
         * ...
         */

        // then, delete the base row
        $needles = array("xa_table","xa_key","xa_id");
        $threads = array(static::$table,static::$key,$id);
        $sql = fglu_sql(FGLU_SQL_DELETE,$needles,$threads);
        $row_count = $wpdb->query($sql);
        if ($row_count === false) {
            fglu_setError(__METHOD__,"SQL Error<br/>$sql<br/>$wpdb->last_error");
            if ($commit) $wpdb->query("ROLLBACK");
            return false;
        } else {
            if ($commit) $wpdb->query("COMMIT");
            $total_count += $row_count;
            return $total_count;
        }

    }
    /**/


}


class FGLU_Activity extends FGLU_Entity {

    // Keys
    public $activity_id;

    // Required Attributes
    public $name;                   
    public $short;                  

    public $activity_cd;            
    public $display_order;          
    public $private = 0;            
    public $school_visit = 0;       
    public $report = 0;             
    public $capacity = 0;           

    // System Attributes

    public $id_user;
    public $dt_updated;

    /*
     * ...
     */

}

?>

GraceRg
  • 23
  • 4
  • show us the code of both classes? – Sindhara Mar 20 '19 at 13:31
  • add it to the question and not as comment – Sindhara Mar 20 '19 at 13:38
  • Child `delete` method will delete what? Maybe it needs `$id` as an argument __too__? – u_mulder Mar 20 '19 at 13:43
  • I've omitted most of the code in the classes, but the point is that the static delete method is not defined in the child. It is simply inherited from the base class. The code works (records get deleted), but it is throwing a warning when PHP is executed with Strict Standards. – GraceRg Mar 20 '19 at 13:52
  • are there any other symbols named `delete` in this class? – Sindhara Mar 20 '19 at 13:53
  • @kuh-chan, thanks for the pointer. As it turns out, delete was overridden and omitted one of the parameters. Thanks again. – GraceRg Mar 20 '19 at 14:28

1 Answers1

1

FGLU_Activity extends FGLU_Entity and does NOT override the static ::delete method.

Any hints as to how to avoid this error the next time i encounter it?

You have a subclass containing a delete() method with arguments that don't match those in the delete() method in the parent class. That's not really an error. If the functionality doesn't match, rename the child method to show this, or if it does but the arguments in the parents are superfluous, add FGLU_Activity($id=NULL,$commit=NULL).

You wouldn't get this error if you hadn't also declared the method in the child class.

Either that or I'm really missing something. Static methods are still subject to standard rules around visibility, inheritance etc so that's not really the issue here.

iamgory
  • 862
  • 1
  • 6
  • 10