473,503 Members | 12,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Universally define __call( ) ?


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 definition to the
prototype for Object.

Is there any way to do that in php 5? I could make every one of my
classes inherit from like an Object class that I define, but that kind
of sucks.

Jul 17 '05 #1
4 1986
MrKrinkle said the following on 09/06/2005 20:38:
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 definition to the
prototype for Object.

Is there any way to do that in php 5? I could make every one of my
classes inherit from like an Object class that I define, but that kind
of sucks.


Hang on, you want to have a load of classes inherit a particular
behaviour, but you don't want to specify that they extend a base class
that defines this behaviour?? Why?

--
Oli
Jul 17 '05 #2


Oli Filth wrote:
MrKrinkle said the following on 09/06/2005 20:38:
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 definition to the
prototype for Object.

Is there any way to do that in php 5? I could make every one of my
classes inherit from like an Object class that I define, but that kind
of sucks.


Hang on, you want to have a load of classes inherit a particular
behaviour, but you don't want to specify that they extend a base class
that defines this behaviour?? Why?

--
Oli


Well, a couple reasons:

A. I want EVERY object in the application to have this behavior.

B. If I've already defined classes (and I have) then I would have to go
back and add "extends MyBaseObject" to all of the root classes. Some
of the classes come from other people, so each time they send me an
update of their source, I'd have to modify it, or get them to do this
for me anyway.

C. Since I'm redefining/overriding the __call function, which is
already on whatever "base" class php has for objects (what would be
"Object" in java), then it makes sense to modify the prototype rather
than invent my own Object class.

In AS 2 this would be easy.

In my experience, asking someone "but why would you want to do that" is
never fruitful, it's usually a way to avoid trying to answer the
question.

Jul 17 '05 #3
MrKrinkle said the following on 11/06/2005 20:43:

Oli Filth wrote:
MrKrinkle said the following on 09/06/2005 20:38:
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 definition to the
prototype for Object.

Is there any way to do that in php 5? I could make every one of my
classes inherit from like an Object class that I define, but that kind
of sucks.

Hang on, you want to have a load of classes inherit a particular
behaviour, but you don't want to specify that they extend a base class
that defines this behaviour?? Why?


Well, a couple reasons:

A. I want EVERY object in the application to have this behavior.

B. If I've already defined classes (and I have) then I would have to go
back and add "extends MyBaseObject" to all of the root classes. Some
of the classes come from other people, so each time they send me an
update of their source, I'd have to modify it, or get them to do this
for me anyway.

C. Since I'm redefining/overriding the __call function, which is
already on whatever "base" class php has for objects (what would be
"Object" in java), then it makes sense to modify the prototype rather
than invent my own Object class.


AFAIK, PHP classes are standalone and are not implicitly derived from a
built-in base class (i.e. not like in Java, for instance). There is no
predefined behaviour for __call().
In AS 2 this would be easy.

In my experience, asking someone "but why would you want to do that" is
never fruitful, it's usually a way to avoid trying to answer the
question.


The answer was implicit in my question: you can't!

PHP (like most OOP languages) is class-based, rather than prototype-based.

If you want a set of classes to share common (customised) functionality,
then you must derive them from a common base class.

--
Oli
Jul 17 '05 #4

Well I don't see how your response implied that answer but thank you
just the same.

Jul 17 '05 #5

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

Similar topics

18
8898
by: Bryan Parkoff | last post by:
"#define" can only be inside the global scope before main() function. "#if" can be tested after "#define" is executed. The problem is that "#define" can't be inside main() function. I do not wish...
2
5562
by: Andreas | last post by:
Hi! I'm using an IplImage library from camellia.sourceforge.net, and the testbench calls a file only containing code like the one below. In cam_morphomaths_code.c the real computation is made,...
3
10556
by: theotyflos | last post by:
Hi all, I have the following: /*--- SNIP ---*/ typedef struct Argument_s { char *address; int type;
9
3079
by: pozz | last post by:
Hi all, I have the below #defines #define NUMBER1 30 #define NUMBER2 50 #define SUM (NUMBER1+NUMBER2) #define STRING1 "Byte: \x30" #define STRING2 "Byte: \x50"...
34
3158
by: BQ | last post by:
Hello Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant, is greater than 35, it returns 56, if not, 20. I would like that at compile time, not at run time. ...
17
2755
by: niraj.tiwari | last post by:
What is meaning of the following define:- #define x(argl...) x1(##argl)
71
33115
by: David T. Ashley | last post by:
Where is the best place to define TRUE and FALSE? Are they in any of the standard include files, ever? Do any standards apply? What I've traditionally done is something like: #ifndef...
1
1930
by: surf | last post by:
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...
23
3883
by: anon.asdf | last post by:
Hello! In the following code-snippet, is it possible to initialize each element of arr, with STRUCT_INIT? struct mystruct { int a; char b; };
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7264
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
7316
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...
0
7449
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
5562
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,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
371
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.