Re: Casting from parent class to child

From: Date: Wed, 06 Oct 2010 16:30:14 +0000
Subject: Re: Casting from parent class to child
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-308510@lists.php.net to get a copy of this message
Casting does not change an object. You must copy the relevant value(s) from the object returned into a new DateTimePlus. Since DateTime's constructor takes only a string, and I assume it won't accept your format directly, you're better off converting the string into a Unix timestamp and creating a new object from that. However, I leave that optimization to you. The following code is sufficient: $plus = new DateTimePlus(); $plus.setTimestamp(parent::createFromFormat("H.i d.m.Y", $string).getTimestamp()); return $plus; David

« previous php.general (#308510) next »