Re: Object method as handler functions in PHP4/Zend
| From: | Zeev Suraski | Date: | Wed, 30 Jun 1999 06:02:51 +0000 |
| Subject: | Re: Object method as handler functions in PHP4/Zend | ||
| References: | 1 2 3 4 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-7882@lists.php.net to get a copy of this message | ||
At 06:49 30/06/99 , Chuck Hagenbuch wrote:
Quoting Zeev Suraski <zeev@zend.com>: No, it doesn't mean that (I was talking about methods that don't really have object contexts). Frankly, I'm not really sure what you're after. You can pass that function a 'pointer' to an object, and a method name, and call $object->$method(). I think you could do that in PHP 3.0, but if you couldn't, you can do it using PHP 4.0. I may have an example that will illustrate the point in question: class foo { function mysort ($a, $b) {Right now, you can't supply 'foo::mysort' as a function name. I'm not sure at all we'd want to add that either. It's a bit complicated for me right now to explain what you can do, what I think we'll add that you'd be able to do, and what I don't think we'll add and you won't be able to do (for example, this). I'll illustrate it when I have a bit more time, I have to run right now. And to answer your question - IF this syntax was possible, this function would have not performed in an object context at all, and thus, have no access to properties of any object. It is completely similar to a static method in C++ or Java. It doesn't really make sense otherwise. If you know you're expecting an object context, make your function accept $obj and $method, and inside the function, call $method() if $obj is empty, or $obj->$method() if it isn't. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.il// blah} function dostuff ($stuffarray) {$sorted = usort($stuffarray, '$this->mysort');} } I couldn't find anything that would work as the second argument to usort; I had to make mysort() a global routine. I take it in php4, you'll at least be able to put 'foo::mysort' as the second argument. However, if mysort() references class variables (ie, it's not a static method - in the java sense, at least), will there be a way to use a reference to a specific object's mysort function?