Re: Function __call

From: Date: Sat, 30 Aug 2008 17:20:40 +0000
Subject: Re: Function __call
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-279099@lists.php.net to get a copy of this message
please keep replies on list unless your intending to pay me an hourly fee ... Diogo Neves schreef:
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 (the function name class_hooker() is very funny btw) and you seem to be mixing static/non-static class calls willy-nilly. 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. your code makes me think of the hooking mechanism in WordPress ... works okay, but it's a nightmare to code to (imho). 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'
On Sat, Aug 30, 2008 at 2:38 PM, Jochem Maas <jochem@iamjochem.com> wrote:
Diogo Neves schreef:
hi all, I'm sending this email only to ask if someone know if the works of __call in private methods is bug or feature. ex. class user { public function __call ( $name, $arguments ) { do something return call_user_func( array( $this, $name ), $arguments );
the fatal error occurs because the method exists, but it's private ... __call() is only called if the method does not exist at all: class user {
      public function __call($m, $a) {
              if (is_callable(array($this, "_".$m)))
                      return $this->{"_".$m}( $a );
      }
      private function _xpto($a)
      {
              var_dump($a);
      }
} $u = new user; $u->xpto(1, 2, 3);
} private function xpto ( $arguments ) { do something } } new $user = new user();
the first 'new' is incorrect me thinks.
$user->xpto(); error: Fatal error: Call to private method user::xpto() from context '' in xpto.php on line 11 PS: what a fucking I was thinking? well, it don't have this public method, then it sholdn't know it exists, then go to __call() i really don't know if it make any sense to someone else, but it still make sense to me any thoughts? ---- ---- Thanks by your attention, Diogo Neves Developer @ Sapo.pt by PrimeIT.pt
---- ---- Thanks by your attention, Diogo Neves Developer @ Sapo.pt by PrimeIT.pt


« previous php.general (#279099) next »