Re: Copying an Object
| From: | Gary | Date: | Fri, 24 Sep 2010 08:09:04 +0000 |
| Subject: | Re: Copying an Object | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-308273@lists.php.net to get a copy of this message | ||
Daniel Kolbo wrote:
> Say you have two classes: human and male. Further, say male extends
> human. Let's say you have a human object. Then later you want to make
> that human object a male object. This seems to be a pretty reasonable
> thing to request of our objects.
I don't think any human can change gender without major surgery, but I
don't know if you just chose your example badly or whether you really
think objects should be able to mutate into other types of object
without some kind of special treatment.
> This type of thing would especially be
> easy if objects of parent classes could be cast as an object of its
> extended class.
Where would the extra data come from to fill in any fields the base
class does not have? Just think of a simple example with a Shape class,
extended by a ColouredShape class which contains some data about the
object's colour - if you have a Shape object it can't become a
ColouredShape without some surgery because bits of the ColouredShape's
anatomy are not present.
--
Gary Please do NOT send me 'courtesy' replies off-list.
PHP 5.2.12 (cli) (built: Jan 14 2010 14:54:11)
1.7.7(0.230/5/3) 2010-08-31 09:58 Cygwin