Re: [SMARTY] implementation-idea for registering plugins as class-methods
| From: | Matthias Mohr | Date: | Thu, 13 Feb 2003 15:54:12 +0000 |
| Subject: | Re: [SMARTY] implementation-idea for registering plugins as class-methods | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7733@lists.php.net to get a copy of this message | ||
> > Here is an idea for the problem, that you cannot use class-methods
> > as plugin-functions.
> >
> > I had a look at the Smarty source-code.
> > To check the existance of a given functionname, you only check it with
> > "function_exists".
> > In my opinion you have to check it first with
> > method_exists( $this, funcname )
> > if it does not exists run through the whole object-parents with
> > get_parent_class(...) and to the same method_exists-call with the parents
> > until you either found a method with the given name or until there are no
> > more parents.
>
> this is unnecessary. a subclass inherits all methods of it's parent-class.
> so a parent-class cannot have a method, that is unknown to it's children.
I think it is necessary.
"method_exists" only returns true, if the method exists in the given object,
not if it exists as derive from a parent class.
So to check the existance of the given function, you have to walk through the
object parents until you find it...
> > Would this be hard to implement?
> > It would solve all the problem and would also be a great step forward!
>
> i think it would be hard.
For my first look it look relatively simple
(change all calls of function_exists to an own function;
extend the _plugins-array, so that it can additionally contain an object;
change the execution of the plugins to check for that object and use it)
But I have no deep insight into the Smarty-sources/structure, so you surely
know it much better.
> why do you want to put everything inside a subclass of class Smarty
> anyway ??
Because
- I like to have everything encapsulated and
- I want access to the methods and variables of the derived class(es) and
- additionally I think it's much more consistent, that an existing class method
inside the current object will be called (if it exists) instead of a global function.
> with the lack of protected variables and with php's limited
> oop-capabilities things can get very complicated und nearly
> undebuggable with deep class-hierarchies and all-in-one objects that
> provide functionality for everything.
I can't contradict, but it mustn't be so complicated, that it leads to problems...
Either I use oop-capabilites or not - but I try not to mix it.
So if I have a class and a functionality which this class represents I try to
put the whole functionality in it and not to put some parts outside.
So I'm able to inherit from the Smarty-class, but it's not possible to use
it consequently.
That's the thing I criticize!
> smarty knows register_object() since 2.4.0 and
> method-calls to those objects. i would try using these first.
You mean to register my objects and then access them inside the plugins?
How will this work?
Or to register one plugin-object and then access that methods instead of
using the plugin-functionality?
This is in my opinion also only a workaround.
Then I'll use global function-wrappers instead.
with regards,
Matthias