Re: Object method as handler functions in PHP4/Zend
| From: | Zeev Suraski | Date: | Wed, 30 Jun 1999 05:58:08 +0000 |
| Subject: | Re: Object method as handler functions in PHP4/Zend | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-7858@lists.php.net to get a copy of this message | ||
At 03:39 30/06/99 , Manuel Lemos wrote:
Hello Zeev, On 30-Jun-99 05:24:09, you wrote:Some pseudo-code examples of what you're after would be nice. If what you're after is a transparent way of passing a method&object combination in place of a function name, and make $funcname() transparently call object->method(), no, there's no way to do it (and I think it's safe to say there won't be one either). But, if you know you're expecting an object+method/property combination, there's nothing that stops you from calling any of these methods in the context of the object, and access any of the object's properties, from wherever you have the object handler and method/property names. You can do it from both PHP code and C code. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.ilYou can call an object method from outside an object in PHP 4.0,using thenotation of classname::method().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. Well, to present an example that you may understand right away, think of a class that is used to parse a specific XML format. Ideally you would use the class methods as the parser's XML element and data handlers and use that variables of the object to store some format specific contextual information. In PHP 3 you can't use the class method functions as handlers. From what you say, that is possible in PHP 4, but you still can't store the object variables to store parsing contextual information. What I am after is some way to pass to the XML functions that set the handler functions, some reference that would let the XML parser call the class methods in the context of a given object. Was this clear enough?Right now, only static strings are accepted for both the class name and the method name, but we may make them dynamic so that you can this notation indirectly.That's better, but I don't know if that solves the reentrancy problem. I'm not sure what you mean by dynamic, but I hope that means you can pass a string as name of a callback function and the function is called in the context of a user defined object of a given class. Thatr would mean that the $this references in the method function reference the functions of the class and the variables of the user defined object.