You are here: using __call() to simulate extending classes « PHP Programming Language « IT news, forums, messages
using __call() to simulate extending classes

Posted by surf on 06/20/07 21:02

We have some open source tools that we use. I don't want to extend
the classes in the tools source because the calls to new() happen in
the tool source and we are supposed to avoid changing the code there
as much as possible, rather I tried to adopt a strategy where I have a
base class variable in my class and I direct all calls I don't want to
handle to the base class through call_user_func_array() after first
intercepting them through __call. I use __get and __set similarly. I
think I got this idea from the PHP cookbook, but I don't have it in
front of me.

Anyway, one problem I found with this approach is that if the base
class defined a pass by reference paramter
such, I'm not sure how to make that work by propgating through my
__call() as apbass by reference.
I got around it for now by declaring each of those functions in my
class directly and calling the base class.

Another problem is that if I pass any call onto the base class, if
some other call farther down the call stack calls a function and I
want it to call back into my class because I have my own definition
for that function, it won't work because the base class doesn't know
about my class and I don't know a good way to do this which I didn't
realize until it came up as an issue. It happens in once place so I
have to copy the code from the tool source and have my own copy of the
top level function. In Perl I think I can put whatever I want into
someone elses namespace, I'm not sure if I can override a method in a
class that someone else declared in PHP which is essentially how it
might have been done in Perl

 

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

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