On Mon, Mar 15, 2010 at 2:14 PM, Larry Garfield <la...@garfieldtech.com>wrote:

> The challenge of "never use extend" is that simply wrapping classes in
> decorators only goes so far.  You can't always maintain interface
> compliance
> if you're nesting decorators, and if you're overriding only one out of a
> dozen
> or two methods then you have a lot of foo() { return $obj->foo(); } method
> implementations.  Aside from being hard to read, that also eats up cycles
> for
> the extra stack calls.  __call() can make it much less code but is also
> much
> slower.
>
> If there were a syntactic-level support for "wrap this object in this class
> and pass through any method that isn't redefined", a sort of sideways
> extends,
> that would become much simpler.  I'm not sure what that would look like,
> though.
>
> Or perhaps this is a good time to revisit the traits proposal from a few
> months back?
>

While traits do seem pretty cool, the fundamental problem appears to be that
Framework X doesn't let me do what I want.  Unfortunately that is the side
effect of using a framework, it does things for you.  I had attempted to
build a system like this in userland code to dynamically replace classes in
my framework, but scrapped it because I could only see ways in which it
would be abused.  If someone replaces a class buried in a framework, that
modifies some bit of functionality, which is depended on by a completely
unrelated area of the framework, it could potentially cause issues that
would be very hard to track down.  This sounds a lot like aspect oriented
programming in the ability to completely overwrite a function with userland
code.

I feel like the better solution is to fix the framework to allow the
flexibility to do what you want in a controlled manner, and not bend the
language to fix the framework.  I don't mean to say that PHP is problem free
or perfect, but I'm not sure this is the best method to fix the problem at
hand.

-- 
-Nathan Gordon

If the database server goes down and there is no code to hear it, does it
really go down?
<esc>:wq<CR>

Reply via email to