473,507 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using __call() to simulate extending classes


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

Jun 20 '07 #1
1 1931
surf wrote:
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
When you are using PHP4, you can extend classes as you would do in Java:

class Foo extends Base {}

Afterwards, you can declare the methods you want to override, and leave out
the ones you want to use unchanged from the base class.

In PHP5, classes and methods can be declared final, which means that you
cannot extend/override them this way.
JW
Jun 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1988
by: MrKrinkle | last post by:
I want to universally define the __call() method, so that every class in my application does the same thing if a non-existant function is called. In actionscript I could do this by adding the...
5
2931
by: needin4mation | last post by:
Hi, I read this in a book about the Xml classes in c#: "These classes are abstract and therefore must be extended." I just wanted to know what this statement means. I know it is not in...
7
1627
by: A Traveler | last post by:
Hello all, i was just curious if anyone whos been playing with VS2005 could tell me... In javascript (and java??) you can alter the prototypes for an object in your project. I dont remember...
9
5768
by: Fat Elvis | last post by:
I'd like to extend some of my Asp.net pages by using Partial Classes. Example ASP.Net Page: public partial class Admin_Customer : System.Web.UI.Page { protected void Page_Load(object sender,...
13
2097
by: interec | last post by:
I have some code in Java that I need to translate into C++. My Java code defines a class hierarchy as follows: // interface IA public interface IA { public abstract void doA(); } //...
21
7241
by: Daz | last post by:
Hi everyone. I am trying to create an extension of the mysqli class within PHP, and I am finding it quite difficult. I am fairly new to PHP classes, and decided to give them a go. Here's what I...
1
1724
by: =?Utf-8?B?Q2Fsdmlu?= | last post by:
Dear all, I had used partial class to extend typed dataset(ex. add a method to TypedDataTable) in my windows-base applications and it works well. But when I try it in a web services project,...
5
2118
by: Wolfgang Hanke | last post by:
Hello, I want to extend multiple Controls like TextBox, Label, ComboBox etc. with the same new featureset (for Example all need a Method getSomething()) Because I cant alter their Base-Class I...
8
2342
by: Floortje | last post by:
Hi i have been struggeling with this question for quite some time now. I have some helper classes that handle images (upload an image, create thumbnails and show a imagelist), links (add link,...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.