[php-src] PR #21366: Fix GH-21362: ReflectionMethod::invoke/invokeArgs() rejects different Closure instances

From: Date: Fri, 06 Mar 2026 22:22:20 +0000
Subject: [php-src] PR #21366: Fix GH-21362: ReflectionMethod::invoke/invokeArgs() rejects different Closure instances
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-35113@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/21366 Author: iliaal ## Summary Fixes #21362 ReflectionMethod::invokeArgs() (and invoke()) for Closure::__invoke() incorrectly accepted any Closure object, not just the one the ReflectionMethod was created from. ### Root cause All Closure objects share a single zend_ce_closure class entry. The instanceof_function() check in reflection_method_invoke() compares class entries, so it always sees zend_ce_closure == zend_ce_closure and passes -- it cannot distinguish between different Closure instances. ### Fix Two changes to ext/reflection/php_reflection.c: 1. **instantiate_reflection_method()**: Store the original Closure object in intern->obj via ZVAL_OBJ_COPY() when reflecting Closure::__invoke(). Previously this was a no-op (/* do nothing, mptr already set */). 2. **reflection_method_invoke()**: After the existing instanceof_function check passes for Closures, add an identity check (Z_OBJ_P(object) != Z_OBJ(intern->obj)) to reject different Closure instances. ### Test ext/reflection/tests/gh21362.phpt covers: - invokeArgs() with the correct Closure (should work) - invokeArgs() with a different Closure (should throw ReflectionException) - invoke() with a different Closure (should throw ReflectionException)

« previous php.git-pulls (#35113) next »