|
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]
|