2012-05-14 33 views

回答

1
class Custom_DateTime extends DateTime 
{ 
    static public function createFromFormat($format, $time) 
    { 
     return new static(); 
    } 
} 

我可能失去了一些東西 - 爲什麼不這只是工作?

+0

如果我從該函數執行此操作:'返回DateTime :: createFromFormat($ format,$ time);' - 我將得到一個'DateTime'對象,對嗎?不是我的子類? – Sonny

+0

添加了另一行,可能工作 – Jeroen

+1

另外,請看看這個:http://stackoverflow.com/questions/5450197/make-datetimecreatefromformat-return-child-class-instead-of-parent – Jeroen