Re: Callling callbacks

From: Date: Thu, 22 Apr 2010 19:21:37 +0000
Subject: Re: Callling callbacks
References: 1 2  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-7187@lists.php.net to get a copy of this message
On Wed, 21 Apr 2010 21:23:10 +0100, Stanislav Malyshev <stas@zend.com> 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

« previous php.pecl.dev (#7187) next »