> > On 9/24/2010 4:09 AM, Gary wrote: >> 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 >> >> > > The colouredShape class would probably have a member variable called > $color. This member could have a default value (as defined in the > class), be defined through the __construct() method (which would be > invoked upon such a cast procedure...perhaps there could be a __cast() > method much like how there is a __clone() method.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php