php - Make DateTime::createFromFormat() return child class instead of parent -
I'm expanding Am I using the following code to solve this problem? Is this the best way? This is a way to go though, because you think what you do Want to provide Extensible DateTime class, I suggest you use If you do not plan to expand the class, then it is not necessary, but if anyone does, then it will prevent them from repeating the same action. DateTime to add some useful methods and constants < P> Everything is okay when using the
new to create a new object, but when using the static method
createFromFormat it always returns the original
DateTime object And certainly none of the hair methods are available.
Name space noilibbs \ datetime; Class datetime extension \ datetime {static public function createFromFormat ($ format, $ time) {$ ext_dt = new self (); $ Ext_dt- & gt; Settimestamp (guardian :: createFromFormat ($ format, time) -> getTimestamp ()); Return $ ext_dt; }}
static instead of
self :
Namespace NoiseLabs \ DateTime; Class Datetime extension \ datetime {stable public function createFromFormat ($ format, $ time) is {$ ext_dt = new static (); $ Ext_dt- & gt; Settimestamp (guardian :: createFromFormat ($ format, $ time) -> getTimestamp ()); Return $ ext_dt; }}
Comments
Post a Comment