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

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.

 

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

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