PHP classes to store table data, column name + type -


i getting error: using $this when not in object context $this->filterarray

so change self::filterarray , error: unknown: non-static method abstract::filterarray() should not called statically

i not sure if have correct or if should using abstract or interface?

basically trying setup array(column_name => type) can use build basic insert forced data type:

    $cols = sentdao::describe();      foreach ($cols $col => $type) {          if (!isset($data[$col])) continue;          switch ($type) {             case self::int:      $value = intval($data[$col]);             case self::text:     $value = $this->escape($data[$col]);             case self::date_now: $value = 'now()';         }          $return[] = " {$col} = '{$value}'";     } 

i didn't want end creating hundreds of different objects , wanted keep simple stored in array.

/**  * abstract  *  */ abstract class accountsabstract {     /**      * data types      */     const int = "int";     const text = "text";     const date_now = "date_now";      /**      * columns data type      * @param  array $filter: exclude columns      * @return array      */     abstract static function describe($filter);      /**      * filter array, unsetting element(s)      * @param string/array $filter - match array key      * @param array filtered      * @return array      */     protected function filterarray($filter, $array)     {         if($filter === null) return $array;          if(is_array($filter)){             foreach($filter $f){                 unset($array[$f]);             }         } else {             unset($array[$filter]);         }          return $array;     } }   class accountsdao extends accountsabstract {     /**      * columns & data types.      * @see accountsabstract::describe()      */     public static function describe($filter)     {         $cols = array(             'account_id' => accountsabstract::int,             'key' => accountsabstract::text,             'config_id' => accountsabstract::int         );          return $this->filterarray($cols, $filter);     } }  /**  * records  */ class accountsrecordsdao extends accountsabstract {     public static function describe($filter)     {         $cols = array(             'record_id' => accountsabstract::int,             'created' => accountsabstract::date_now,             'customer_id' => accountsabstract::int         );          return $this->filterarray($cols, $filter);     } }  /**  * config  */ class accountsconfigdao extends accountsabstract {     public static function describe($filter)     {         $cols = array(             'config_id' => accountsabstract::int,             'hidden' => accountsabstract::int,             'language_id' => accountsabstract::int         );          return $this->filterarray($cols, $filter);     } } 

also think using full class name makes code messy , less portable: accountsabstract::int, there way use self::int instead? or should create these private properties though never going change referenced.

you're calling filterarray static method, means have no $this instance.

as implementation of filterarray doesn't seem require $this, make static method , call via self::filterarray($filter, $array)


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -