Posted by justin.demaris@gmail.com on 05/25/07 16:20
The trick I usually use if I need to do something similar to that is
to create a constructor for the subclass that takes the parent class
as its only parameter. Then you just do
$obj = new Blah();
$obj = new EnhancedBlah($obj);
Same type of effect and you can still use the $obj anywhere you have
before because its a subclass now.
On May 25, 2:07 am, Ryan van Roode <rvanro...@gmail.com> 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
[Back to original message]
|