You are here: Re: downcasting in php « PHP Programming Language « IT news, forums, messages
Re: downcasting in php

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация