You are here: Re: Extending classes at runtime « PHP Programming Language « IT news, forums, messages
Re: Extending classes at runtime

Posted by C. on 09/06/07 12:12

On 6 Sep, 09:59, Dikkie Dik <dik...@nospam.org> wrote:
> Dikkie Dik wrote:
> > ptd...@gmail.com wrote:
> >> Hi everybody,
>
> >> one of the most powerful things about ruby is its ability to add
> >> funcionality to a class (or an instance of a class) at runtime. Can
> >> anyone please tell me if this can be done with php?
>
> >> thanks a million
>
> > You could search the manual for "magic methods" and follow the link
> > "overloading". It may not be what you would do in Ruby, but it should
> > get you the same possibilities.
>
> Sorry to follow up on my own post, but you can combine these techniques
> with "callback functions". You might want to take a look on that topic also.

You could create a string with a new sub-class and eval() it ...

$classname='revised';
$newdef=' class ' . $classname . ' extends baseClass {
function extension() { print "Hello world\n"; }
}'
eval($newdef);
$obj=new $classname();

(not tested)
but I find it difficult to see any value in doing this at runtime -
and it opens up a attack vector.

C.

 

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

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