So, I have an abstract class that has a function called "create" which inserts stuff into the database if they are in the an array which is supplied as a parameter. It's a static function defined like this:
/**
* create($fields)
* Creates a thing in the database using the supplied array of fields.
* @param $fields the fields with keys as their column and values as their rows.
* @param $validFields an array with a list of valid fields.
* @param $tableName since this is a static function we need the table to insert to.
*/
static function create(array $fields, $tableName, $validFields)
{
$keys = "";
$values = "";
foreach($fields as $key => $value)
{
if(in_array("$key", $validFields) && !empty($value))
{
$keys .= "$key,";
$values .="'$value',";
}
}
$keys = rtrim($keys, ",");
$values = rtrim($values, ",");
$mysql = new Mysql_Wrapper();
return $mysql->query("INSERT INTO $tableName($keys) VALUES($values)");
}
and this works, it's in the main abstract class. Now to implement this I make a "create" function in the inheriting class and call the create function with the parameters, but I was wondering, since this is an abstract class, is there some way I can make some constant abstract fields in the class, and implement them in the inheriting class in order to remove the need of redefining the function in the inheriting class just to add the validFields and the tableName. Is there anyway to do this?