2012-05-14 34 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