-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Infer static for closures #19941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Infer static for closures #19941
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,7 @@ class Test { | |
|
||
?> | ||
--EXPECT-- | ||
object(Test)#1 (0) { | ||
} | ||
NULL | ||
object(Test)#1 (0) { | ||
} | ||
object(Test)#1 (0) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,14 +75,19 @@ ZEND_METHOD(Closure, __invoke) /* {{{ */ | |
/* }}} */ | ||
|
||
static bool zend_valid_closure_binding( | ||
zend_closure *closure, zval *newthis, zend_class_entry *scope) /* {{{ */ | ||
zend_closure *closure, zval **newthis_ptr, zend_class_entry *scope) /* {{{ */ | ||
{ | ||
zval *newthis = *newthis_ptr; | ||
zend_function *func = &closure->func; | ||
bool is_fake_closure = (func->common.fn_flags & ZEND_ACC_FAKE_CLOSURE) != 0; | ||
if (newthis) { | ||
if (func->common.fn_flags & ZEND_ACC_STATIC) { | ||
zend_error(E_WARNING, "Cannot bind an instance to a static closure, this will be an error in PHP 9"); | ||
return 0; | ||
// FIXME: Restrict this workaround to implicitly static closures? | ||
// Will need an additional fn_flag. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a |
||
zend_object *obj = Z_OBJ_P(newthis); | ||
ZVAL_UNDEF(newthis); | ||
GC_DTOR(obj); | ||
*newthis_ptr = NULL; | ||
} | ||
|
||
if (is_fake_closure && func->common.scope && | ||
|
@@ -144,13 +149,14 @@ ZEND_METHOD(Closure, call) | |
|
||
closure = (zend_closure *) Z_OBJ_P(ZEND_THIS); | ||
|
||
newobj = Z_OBJ_P(newthis); | ||
newclass = newobj->ce; | ||
newclass = Z_OBJ_P(newthis)->ce; | ||
|
||
if (!zend_valid_closure_binding(closure, newthis, newclass)) { | ||
if (!zend_valid_closure_binding(closure, &newthis, newclass)) { | ||
return; | ||
} | ||
|
||
newobj = newthis ? Z_OBJ_P(newthis) : NULL; | ||
|
||
fci_cache.called_scope = newclass; | ||
fci_cache.object = fci.object = newobj; | ||
|
||
|
@@ -241,16 +247,16 @@ static void do_closure_bind(zval *return_value, zval *zclosure, zval *newthis, z | |
ce = NULL; | ||
} | ||
|
||
if (!zend_valid_closure_binding(closure, newthis, ce)) { | ||
return; | ||
} | ||
|
||
if (newthis) { | ||
called_scope = Z_OBJCE_P(newthis); | ||
} else { | ||
called_scope = ce; | ||
} | ||
|
||
if (!zend_valid_closure_binding(closure, &newthis, ce)) { | ||
return; | ||
} | ||
|
||
zend_create_closure(return_value, &closure->func, ce, called_scope, newthis); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.