Ben usul şeklinde oldukça fazlaydı PHP öğrendim, daha geçenlerde şeyler yapmanın OOP şekilde adapte çalışıyordum. Hoever ben izliyordum öğreticiler bağlama geç statik tanıtıldı PHP 5.3 öncesi üretildi.
Ne bilmek istiyorum, bir üst sınıftan bir işlevi çağırırken ben self başvuru nasıl olduğunu.
Örneğin bu iki yöntem DatabaseObject bir çocuk olan bir kullanıcı sınıfı için yazılmıştır. Şu anda onlar ben DatabaseObject içine dahil edilmesi onları teşvik etmek istiyorum DatabaseObject diğer çocuk sınıflar kullanılan konum olarak, kullanıcı sınıfı içinde oturan, ancak ediyoruz.
public static function find_all()
{
global $database;
$result_set = self::find_by_sql("select * from ".self::$table_name);
return $result_set;
}
ve:
protected function cleaned_attributes()
{
global $database;
$clean_attributes = array();
foreach($this->attributes() as $key => $value)
{
$clean_attributes[$key] = $database->escape_value($value);
}
return $clean_attributes;
}
Yani üç soru var:
1) How do I change the self:: reference when I move it to the parent. Is it static:: or something similar?
2) When calling the function from my code do I call it in the same way, as a function of the child class eg User::find_all() or is there a change there also?
3) Is there anything else I need to know before I start chopping bits up?