* Alex Hogan <[EMAIL PROTECTED]>:
>> Keep in mind the above is still in beta, but will allow you to
>> add/remove/redefine methods of objects at runtime. 
>
> You'll have to excuse me form my ignorance, but why would you want to
> add, remove or redefine methods of objects at runtime?
>
> I understand object overloading, but are you talking about something else?

I can think of some good reasons -- the one that readily leaps to mind
is a plugin architecture. 

In perl, you have namespaces, and multiple files can share the same
namespace. This is handy because it allows you to separate classes over
multiple files, and also to dynamically add methods/properties to your
class when needed. For instance, let's say you have a base class that
has the following methods:

    init()
    run()
    load_config()

Now, you could easily extend the class and add new methods, of course;
that's worked in PHP OOP since the beginning. But what if you end up
with three subclasses, each adding methods as follows:

    Sub1::error()
    Sub2::validate()
    Sub3::login()

The problem arises when you want to get a combination of these
subclasses for a single class; how do you do it without creating a new
class? For instance, if I need an object that has the methods of the
base class, plus error() and validate(), how do I do it without making a
fourth subclass that duplicates the methods of Sub1 and Sub2?

As I mentioned above, this is (fairly) trivial to do in perl, as you can
have them use the same namespace and dynamically import methods from
other files into your class. How does one do the same in PHP?

I think the overloading introduced in PHP5 *may* help -- you could look
to see if a file with a name matching the method called exists, load it
into a variable, and then add a function dynamically. I'd need to test
something like this pretty rigorously, though.

-- 
Matthew Weier O'Phinney           | mailto:[EMAIL PROTECTED]
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to