Re: Function __call

From: Date: Sat, 30 Aug 2008 18:34:24 +0000
Subject: Re: Function __call
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-279105@lists.php.net to get a copy of this message
Diogo Neves schreef:
Hi, On Sat, Aug 30, 2008 at 6:20 PM, Jochem Maas <jochem@iamjochem.com> wrote:
please keep replies on list unless your intending to pay me an hourly fee ...
Yeap, i'm new in the list and i missed te cc of list... i'll try to remember, sorry
okay.
Diogo Neves schreef:
Now in understand "schreef" is from da system...
no my email client in in dutch ... it means 'wrote' ... actually that's in the list archives already :-)
On Sat, Aug 30, 2008 at 4:40 PM, Jochem Maas <jochem@iamjochem.com> wrote:
Diogo Neves schreef:
...
nop... I wanna manipulate the $this and the $arguments, and possible don't even execute the private method... I'm tring to develop a "hook system" for my classes... and i simple don't wanna to do all the hook verification every method of the class I'll send my files for you to see what I'm doing in "do something" on my __call() funtion
the code looks messy what with the global $hooks, functions required for hooking
Yeap, but i'm only making tests... i'm not too horried about mess yet...
(the function name class_hooker() is very funny btw)
ok... i missed that in my english... added :)
and you seem to be mixing static/non-static class calls willy-nilly.
I'm never calling something static, i'm?
er, no ... but I had to re-read the code a few times.
I'd rethink this if I we're you. if every can be hooked, then make the hooking should be part of a base class, possibly a factory method for object creation will help to keep things clean and in one place. a generic 'hooking' decorator object might also be an idea. or maybe just using subclasses to change/augment behaviour is a much simpler and cleaner approach.
yep... i'm thinking of a base class, but that has nothing to do with the __call, if u see, i'm already passing the "get_class( $this )" and not __CLASS__ on call_user_func of the user, but again only testing
your code makes me think of the hooking mechanism in WordPress ... works okay, but it's a nightmare to code to (imho).
right again, i'm trying to do a wapper for phpbb class's that have a similar hook system, but needs to be defined method by method, function by function... like a big mess... and even like that i don't get yet the criteria to have a hook or not :)
as you are finding out, creating an elegant solution to this problem is not as easy as it may seem ... especially if you stuck with integrating to a 3rd party application.
BTW. function and method names beginning with '__' are considered reserved by the engine, it's not best practice to name userland functions/methods things like '__magic'
Yeap, in this case is my naming that is really pretty bad, but i needed something diferent from the normal hookable methods, then I simple added a '_'... but again tests, naming and code organization was not a horry, only logic...
the single prefixed underscore to private method names will probably be the easiest implementation ... note that passing every method call via __call() is a rather large performance hit.
But again, i don't see why your php should see your class's private methods outside of itself, it should simple look for a public one, if it exists then call it, otherwise call the _call and let it handle it :S Anyway, thanks for answer me and give me that points, and if u know a really good hoking system, please give me reference ;)
I guess AdultFriendFinder is not the right answer :-P
And please anyone else has an opinion of it should work or not?
again, NO it should NOT. it was not designed that way. search the archives of internals@lists.php.net for a possible answer as to why, and you might considering asking that list why it doesn't work the way you think it should ... note that I doubt very much it will change because such a change would incur major BC breakage.
Thanks


« previous php.general (#279105) next »