|
Posted by Schraalhans Keukenmeester on 05/25/07 08:55
At Fri, 25 May 2007 10:18:48 +0200, gosha bine let his monkeys type:
> On 25.05.2007 08:07 Ryan van Roode wrote:
>> Hello,
>>
>> An API function gives me an object of class 'Blah'. I have subclassed
>> 'Blah' and added a few methods:
>>
>> class EnhancedBlah extends Blah {
>> function enhancement1() {}
>> function enhancement2() {}
>> }
>>
>> Is there a way to 'downcast' the object to a subclass? Something like
>> this:
>>
>> $blah = SuperApi::getBlah();
>> $enhancedBlah = (EnhancedBlah) $blah;
>>
>> Thanks for your help.
>>
>> ~RvR
>>
>
> Technically that's possible, see e.g. http://www.tagarga.com/blok/on/061130
>
> but as others already said, the very idea is wrong.
The effect may be comparable to a sort of cast, but it isn't. It's simply
(ab)using the serialize function to copy just the vars/values and not the
methods of another class.
If OP has a need to do such a thing he probably should loook at his class
design compared to what he was trying to achieve at a more abstract level.
Good chance his original design is flawed.
Sh.
Sh.
[Back to original message]
|