@@ -75,14 +75,19 @@ ZEND_METHOD(Closure, __invoke) /* {{{ */
7575/* }}} */
7676
7777static bool zend_valid_closure_binding (
78- zend_closure * closure , zval * newthis , zend_class_entry * scope ) /* {{{ */
78+ zend_closure * closure , zval * * newthis_ptr , zend_class_entry * scope ) /* {{{ */
7979{
80+ zval * newthis = * newthis_ptr ;
8081 zend_function * func = & closure -> func ;
8182 bool is_fake_closure = (func -> common .fn_flags & ZEND_ACC_FAKE_CLOSURE ) != 0 ;
8283 if (newthis ) {
8384 if (func -> common .fn_flags & ZEND_ACC_STATIC ) {
84- zend_error (E_WARNING , "Cannot bind an instance to a static closure, this will be an error in PHP 9" );
85- return false;
85+ if (!(func -> common .fn_flags2 & ZEND_ACC2_INFERRED_STATIC )) {
86+ zend_error (E_WARNING , "Cannot bind an instance to a static closure, this will be an error in PHP 9" );
87+ return false;
88+ } else {
89+ * newthis_ptr = NULL ;
90+ }
8691 }
8792
8893 if (is_fake_closure && func -> common .scope &&
@@ -144,13 +149,14 @@ ZEND_METHOD(Closure, call)
144149
145150 closure = (zend_closure * ) Z_OBJ_P (ZEND_THIS );
146151
147- newobj = Z_OBJ_P (newthis );
148- newclass = newobj -> ce ;
152+ newclass = Z_OBJ_P (newthis )-> ce ;
149153
150- if (!zend_valid_closure_binding (closure , newthis , newclass )) {
154+ if (!zend_valid_closure_binding (closure , & newthis , newclass )) {
151155 return ;
152156 }
153157
158+ newobj = newthis ? Z_OBJ_P (newthis ) : NULL ;
159+
154160 fci_cache .called_scope = newclass ;
155161 fci_cache .object = fci .object = newobj ;
156162
@@ -241,16 +247,16 @@ static void do_closure_bind(zval *return_value, zval *zclosure, zval *newthis, z
241247 ce = NULL ;
242248 }
243249
244- if (!zend_valid_closure_binding (closure , newthis , ce )) {
245- return ;
246- }
247-
248250 if (newthis ) {
249251 called_scope = Z_OBJCE_P (newthis );
250252 } else {
251253 called_scope = ce ;
252254 }
253255
256+ if (!zend_valid_closure_binding (closure , & newthis , ce )) {
257+ return ;
258+ }
259+
254260 zend_create_closure (return_value , & closure -> func , ce , called_scope , newthis );
255261}
256262
0 commit comments