Re: [PECL-DEV] Callling callbacks
[email protected] ("Gustavo Lopes") Thu, 22 Apr 2010 20:21:37 +0100
| Newsgroups | php.pecl.dev |
|---|---|
| Organization | NĂșcleo de Eng. BiomĂ©di ca do IST |
| Message-ID | <op.vbkv2btgidpuyk@damnation> |
On Wed, 21 Apr 2010 21:23:10 +0100, Stanislav Malyshev <[email protected]> wrote: > Hi! > >> What is the best way to have a function accept an arbitrary callback (be >> it a string, array or closure in case of PHP 5.3) that is compatible >> with PHP 5.2 and 5.3? > > In 5.3+, you should use "f" parameter character. Unfortunately, in 5.2 > there was none, so you'd probably have to have different code in 5.2 > branch. > Apparently, the "f" parameters character also exists in 5.2, it simply wasn't used in the standard extension. However, I'm starting to think I shouldn't use the "f" parameter. I don't want to call the callback immediately (before returning) so my initial approach was to store zend_fcall_info (and its function_name zval) and zend_fcall_info_cache. Well, in 5.2 I couldn't get it to work. If I did something like func(array(new A(), 'method')) the object of type A would be destroyed by the time the callback was called and the data in zend_fcall_info(_cache) would be outdated (in particular fic(_cache).object_pp would point to nowhere). I suppose you could fiddle with the refcounts, but it made me think that storing zend_fcall_info(_cache) was not the correct approach. So which is it? Accepting the callback as a zval*, increment its refcount and store it and then creating zend_fcall_info(_cache) on each callback execution using zend_fcall_info_init? Thanks -- Gustavo Lopes