Object method as handler functions in PHP4/Zend

From: Date: Tue, 29 Jun 1999 04:29:17 +0000
Subject: Object method as handler functions in PHP4/Zend
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-7794@lists.php.net to get a copy of this message
Hello, Unfortunately, some core PHP functions take names of global functions parameters for callback handlers. I say unfortunately because sometimes I need to have a callback function to call a method of a given object, and since currently there is no way to specify a object method as call back handler function, I have to use a global stub function. This is not good because I need have access to context that is provided by the object, so I have resort to global variables. For those that question it, global variables are not bad just because a programming teached said so, but because: a) You will have an hard to make functions reentrant if they get their context from global variables. b) Global variable names of different modules may collide. If you are programming using component modules that you got from somebody else, you have to edit the code solve name collision. If PHP 4 may run compiled code you might not even be able to edit the code. So, I have a couple of suggestions to help improving these problems. For passing object methods as callback function names, we could have a function that would convert a reference to method of a object into some magic name that PHP interpreter could recognize and revert to determine which method of which object when that string would be dereference to call for instance as callback function. To avoid global name collision, we might not need to resort to name spaces. How about having a similar scope control like static in C? Regards, Manuel Lemos Web Programming Components using PHP Classes. Look at: http://phpclasses.UpperDesign.com/ -- E-mail: mlemos@acm.org URL: http://www.mlemos.e-na.net/ PGP key: finger://mlemos@zeus.ci.ua.pt --

« previous php.dev (#7794) next »