Skip to content

Language: static closure bindTo/bind Error parity (#4613) - #4619

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-4613-static-closure-bind
Jun 2, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-4613-static-closure-bind

Conversation

@PurHur

@PurHur PurHur commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Reject Closure::bindTo($obj) and Closure::bind($fn, $obj, …) when the closure is a static function — throws catchable Error: Cannot bind static closure to object (Zend zend_closures.c).
  • bindTo(null) / unbind remains allowed on static closures.
  • VM: ClosureState::isStaticClosure() reads PHPCfg\Func::FLAG_STATIC from the closure block; guard in ClosureSupport::bindTo().
  • JIT: closureIsStatic on closure variables, __closure_is_static on Closure objects, compile-time and runtime guards in ClosureBindHelper.

php-src reference

  • Zend/zend_closures.c — zend_closure_bind(), static-closure guard

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/compliance/ClosureVMTest.php --filter static_closure_bind'
# OK (1 test)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/jit.php /tmp/repro4613.php  # repro from issue
'
# Error: Cannot bind static closure to object
# exit 0

Issue repro (bin/vm.php / Zend PHP parity):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/compliance/ClosureVMTest.php --filter static_closure_bind'

Closes #4613

Made with Cursor

Reject binding $this on static anonymous closures in VM and JIT to match
Zend/zend_closures.c; allow bindTo(null). Add compliance PHPT.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit a1aba27 into master Jun 2, 2026
@PurHur
PurHur deleted the agent/issue-4613-static-closure-bind branch June 2, 2026 20:06
PurHur added a commit that referenced this pull request Jun 18, 2026
Fix already on master via #4619; repro guards bindTo/bind Error parity
matching Zend when binding a static closure to an object.

Co-authored-by: PurHur <PurHur@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language: static closure bindTo()/bind() with $this must Error (Zend/zend_closures.c parity)

1 participant