473,656 Members | 2,793 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 1994
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
8917
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 to create multiple functions which they look almost identical in C++ source code. The C++ compiler should be able to compile one Test() function into two almost identical functions before they are translated into the machine language object. ...
2
5588
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, but I don't understand where cam_morphomaths_code.c is included and how to set what parameters to use in the testbench. How does this code execure? I don't understand a bit...
3
10570
by: theotyflos | last post by:
Hi all, I have the following: /*--- SNIP ---*/ typedef struct Argument_s { char *address; int type;
9
3088
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" If I change NUMBER1 and NUMBER2 I must change STRING1 and STRING2 consequently.
34
3190
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. So: #define FUNCT(x) x>35?56:20
17
2768
by: niraj.tiwari | last post by:
What is meaning of the following define:- #define x(argl...) x1(##argl)
71
33186
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 (TRUE) #define TRUE (1)
1
1946
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 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...
23
3904
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
8382
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8717
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8498
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7311
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.