@@ -192,30 +192,22 @@ ZEND_METHOD(Closure, call)
192
192
}
193
193
/* }}} */
194
194
195
- static void do_closure_bind (zval * return_value , zval * zclosure , zval * newthis , zval * scope_arg )
195
+ static void do_closure_bind (zval * return_value , zval * zclosure , zval * newthis , zend_object * scope_obj , zend_string * scope_str )
196
196
{
197
197
zend_class_entry * ce , * called_scope ;
198
198
zend_closure * closure = (zend_closure * ) Z_OBJ_P (zclosure );
199
199
200
- if (scope_arg != NULL ) { /* scope argument was given */
201
- if (Z_TYPE_P (scope_arg ) == IS_OBJECT ) {
202
- ce = Z_OBJCE_P (scope_arg );
203
- } else if (Z_TYPE_P (scope_arg ) == IS_NULL ) {
204
- ce = NULL ;
205
- } else {
206
- zend_string * tmp_class_name ;
207
- zend_string * class_name = zval_get_tmp_string (scope_arg , & tmp_class_name );
208
- if (zend_string_equals_literal (class_name , "static" )) {
209
- ce = closure -> func .common .scope ;
210
- } else if ((ce = zend_lookup_class (class_name )) == NULL ) {
211
- zend_error (E_WARNING , "Class \"%s\" not found" , ZSTR_VAL (class_name ));
212
- zend_tmp_string_release (tmp_class_name );
213
- RETURN_NULL ();
214
- }
215
- zend_tmp_string_release (tmp_class_name );
200
+ if (scope_obj ) {
201
+ ce = scope_obj -> ce ;
202
+ } else if (scope_str ) {
203
+ if (zend_string_equals (scope_str , ZSTR_KNOWN (ZEND_STR_STATIC ))) {
204
+ ce = closure -> func .common .scope ;
205
+ } else if ((ce = zend_lookup_class (scope_str )) == NULL ) {
206
+ zend_error (E_WARNING , "Class \"%s\" not found" , ZSTR_VAL (scope_str ));
207
+ RETURN_NULL ();
216
208
}
217
- } else { /* scope argument not given; do not change the scope by default */
218
- ce = closure -> func . common . scope ;
209
+ } else {
210
+ ce = NULL ;
219
211
}
220
212
221
213
if (!zend_valid_closure_binding (closure , newthis , ce )) {
@@ -234,25 +226,34 @@ static void do_closure_bind(zval *return_value, zval *zclosure, zval *newthis, z
234
226
/* {{{ Create a closure from another one and bind to another object and scope */
235
227
ZEND_METHOD (Closure , bind )
236
228
{
237
- zval * newthis , * zclosure , * scope_arg = NULL ;
238
-
239
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oo!|z" , & zclosure , zend_ce_closure , & newthis , & scope_arg ) == FAILURE ) {
240
- RETURN_THROWS ();
241
- }
229
+ zval * zclosure , * newthis ;
230
+ zend_object * scope_obj = NULL ;
231
+ zend_string * scope_str = ZSTR_KNOWN (ZEND_STR_STATIC );
232
+
233
+ ZEND_PARSE_PARAMETERS_START (2 , 3 )
234
+ Z_PARAM_OBJECT_OF_CLASS (zclosure , zend_ce_closure )
235
+ Z_PARAM_OBJECT_OR_NULL (newthis )
236
+ Z_PARAM_OPTIONAL
237
+ Z_PARAM_OBJ_OR_STR_OR_NULL (scope_obj , scope_str )
238
+ ZEND_PARSE_PARAMETERS_END ();
242
239
243
- do_closure_bind (return_value , zclosure , newthis , scope_arg );
240
+ do_closure_bind (return_value , zclosure , newthis , scope_obj , scope_str );
244
241
}
245
242
246
243
/* {{{ Create a closure from another one and bind to another object and scope */
247
244
ZEND_METHOD (Closure , bindTo )
248
245
{
249
- zval * newthis , * scope_arg = NULL ;
250
-
251
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "o!|z" , & newthis , & scope_arg ) == FAILURE ) {
252
- RETURN_THROWS ();
253
- }
246
+ zval * newthis ;
247
+ zend_object * scope_obj = NULL ;
248
+ zend_string * scope_str = ZSTR_KNOWN (ZEND_STR_STATIC );
249
+
250
+ ZEND_PARSE_PARAMETERS_START (1 , 2 )
251
+ Z_PARAM_OBJECT_OR_NULL (newthis )
252
+ Z_PARAM_OPTIONAL
253
+ Z_PARAM_OBJ_OR_STR_OR_NULL (scope_obj , scope_str )
254
+ ZEND_PARSE_PARAMETERS_END ();
254
255
255
- do_closure_bind (return_value , getThis (), newthis , scope_arg );
256
+ do_closure_bind (return_value , getThis (), newthis , scope_obj , scope_str );
256
257
}
257
258
258
259
static ZEND_NAMED_FUNCTION (zend_closure_call_magic ) /* {{{ */ {
0 commit comments