require_once ("db.php");
class news {
public $id;
public $title;
public $text;
public function find_by_sql($sql = "") {
global $db;
$result_set = $db->query ( $sql );
$object_array = array ();
while ( $row = $db->fetch_array ( $result_set ) ) {
$object_array [] = self::instantiate ( $row ,$object);
}
return $object_array;
}
private static function instantiate($record ,$object) {
foreach ( $record as $attribute => $value ) {
if ($object->has_attribute ( $attribute )) {
$object->$attribute = $value;
}
}
return $object;
}
private function has_attribute($attribute) {
$object_vars = $this->attributes();
return array_key_exists ( $attribute, $object_vars );
}
public function attributes(){
return get_object_vars ( $this );
}