| re: Universally define __call( ) ?
MrKrinkle said the following on 11/06/2005 20:43:[color=blue]
>
> Oli Filth wrote:
>[color=green]
>>MrKrinkle said the following on 09/06/2005 20:38:
>>[color=darkred]
>>>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.
>>>[/color]
>>
>>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?
>>[/color]
>
> 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.[/color]
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().
[color=blue]
> 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.
>[/color]
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 |