Universally define __call( ) ?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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

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.

Re: Universally define __call( ) ?

MrKrinkle said the following on 09/06/2005 20:38:
Quoted text here. Click to load it

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?


Re: Universally define __call( ) ?

Oli Filth wrote:
Quoted text here. Click to load it

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

Re: Universally define __call( ) ?

MrKrinkle said the following on 11/06/2005 20:43:
Quoted text here. Click to load it

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().

Quoted text here. Click to load it

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.


Re: Universally define __call( ) ?

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

Site Timeline