@@ -174,14 +174,12 @@ static double opencensus_now()
174174}
175175
176176/**
177- * Call the provided Closure with the provided parameters to the traced
178- * function. The Closure must return an array or an E_WARNING is raised.
177+ * Call the provided callback with the provided parameters to the traced
178+ * function. The callback must return an array or an E_WARNING is raised.
179179 */
180- static int opencensus_trace_zend_fcall_closure (zend_execute_data * execute_data , opencensus_trace_span_t * span , zval * closure , zval * closure_result TSRMLS_DC )
180+ static int opencensus_trace_call_user_function_callback (zend_execute_data * execute_data , opencensus_trace_span_t * span , zval * callback , zval * callback_result TSRMLS_DC )
181181{
182182 int i , num_args = EX_NUM_ARGS (), has_scope = 0 ;
183- zend_fcall_info fci ;
184- zend_fcall_info_cache fcc ;
185183 zval * args = emalloc ((num_args + 1 ) * sizeof (zval ));
186184
187185 if (getThis () == NULL ) {
@@ -195,28 +193,7 @@ static int opencensus_trace_zend_fcall_closure(zend_execute_data *execute_data,
195193 ZVAL_ZVAL (& args [i + has_scope ], EX_VAR_NUM (i ), 0 , 1 );
196194 }
197195
198- if (zend_fcall_info_init (
199- closure ,
200- 0 ,
201- & fci ,
202- & fcc ,
203- NULL ,
204- NULL
205- TSRMLS_CC
206- ) != SUCCESS ) {
207- efree (args );
208- return FAILURE ;
209- };
210-
211- ZVAL_NULL (closure_result );
212-
213- fci .retval = closure_result ;
214- fci .params = & args [0 ];
215- fci .param_count = num_args + has_scope ;
216-
217- fcc .initialized = 1 ;
218-
219- if (zend_call_function (& fci , & fcc TSRMLS_CC ) != SUCCESS ) {
196+ if (call_user_function_ex (EG (function_table ), NULL , callback , callback_result , num_args + has_scope , args , 0 , NULL ) != SUCCESS ) {
220197 efree (args );
221198 return FAILURE ;
222199 }
@@ -226,7 +203,7 @@ static int opencensus_trace_zend_fcall_closure(zend_execute_data *execute_data,
226203 return FAILURE ;
227204 }
228205
229- if (Z_TYPE_P (closure_result ) != IS_ARRAY ) {
206+ if (Z_TYPE_P (callback_result ) != IS_ARRAY ) {
230207 /* only raise the warning if the closure succeeded */
231208 php_error_docref (NULL , E_WARNING , "Trace callback should return array" );
232209 return FAILURE ;
@@ -237,21 +214,23 @@ static int opencensus_trace_zend_fcall_closure(zend_execute_data *execute_data,
237214
238215/**
239216 * Handle the callback for the traced method depending on the type
240- * - if the zval is an array, then assume it's the trace span initialization
217+ * - if the zval is an associative array, then assume it's the trace span initialization
241218 * options
219+ * - if the zval is an array that looks like a callable, then assume it's a callable
242220 * - if the zval is a Closure, then execute the closure and take the results as
243221 * the trace span initialization options
244222 */
245223static void opencensus_trace_execute_callback (opencensus_trace_span_t * span , zend_execute_data * execute_data , zval * span_options TSRMLS_DC )
246224{
247- if (Z_TYPE_P (span_options ) == IS_ARRAY ) {
248- opencensus_trace_span_apply_span_options (span , span_options );
249- } else if ( (Z_TYPE_P (span_options ) == IS_OBJECT ) &&
250- (Z_OBJCE_P (span_options ) == zend_ce_closure )) {
251- zval closure_result ;
252- if (opencensus_trace_zend_fcall_closure (execute_data , span , span_options , & closure_result TSRMLS_CC ) == SUCCESS ) {
253- opencensus_trace_span_apply_span_options (span , & closure_result );
225+ zend_string * callback_name ;
226+ if (zend_is_callable (span_options , 0 , & callback_name )) {
227+ zval callback_result ;
228+ if (opencensus_trace_call_user_function_callback (execute_data , span , span_options , & callback_result TSRMLS_CC ) == SUCCESS ) {
229+ opencensus_trace_span_apply_span_options (span , & callback_result );
254230 }
231+ zend_string_release (callback_name );
232+ } else if (Z_TYPE_P (span_options ) == IS_ARRAY ) {
233+ opencensus_trace_span_apply_span_options (span , span_options );
255234 }
256235}
257236
@@ -534,7 +513,7 @@ void opencensus_trace_execute_internal(INTERNAL_FUNCTION_PARAMETERS)
534513 * Register the provided function for tracing.
535514 *
536515 * @param string $functionName
537- * @param array|Closure $handler
516+ * @param array|callable $handler
538517 * @return bool
539518 */
540519PHP_FUNCTION (opencensus_trace_function )
@@ -565,7 +544,7 @@ PHP_FUNCTION(opencensus_trace_function)
565544 *
566545 * @param string $className
567546 * @param string $methodName
568- * @param array|Closure $handler
547+ * @param array|callable $handler
569548 * @return bool
570549 */
571550PHP_FUNCTION (opencensus_trace_method )
0 commit comments