File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -120,14 +120,15 @@ public static function isStatic(callable $callable): bool
120120 public static function unwrap (\Closure $ closure ): callable |array
121121 {
122122 $ r = new \ReflectionFunction ($ closure );
123+ $ class = $ r ->getClosureScopeClass ()?->name;
123124 if (str_ends_with ($ r ->name , '} ' )) {
124125 return $ closure ;
125126
126- } elseif ($ obj = $ r ->getClosureThis ()) {
127+ } elseif (( $ obj = $ r ->getClosureThis ()) && $ obj ::class === $ class ) {
127128 return [$ obj , $ r ->name ];
128129
129- } elseif ($ class = $ r -> getClosureScopeClass () ) {
130- return [$ class-> name , $ r ->name ];
130+ } elseif ($ class ) {
131+ return [$ class , $ r ->name ];
131132
132133 } else {
133134 return $ r ->name ;
Original file line number Diff line number Diff line change @@ -158,6 +158,8 @@ test('object methods', function () {
158158
159159 Assert::same ('Test::privateFun ' , getName (Callback::toReflection ([$ test , 'privateFun ' ])));
160160 Assert::same ('Test::privateFun ' , getName (Callback::toReflection ($ test ->createPrivateClosure ())));
161+
162+ Assert::same (['Test ' , 'privateFun ' ], Callback::unwrap ((new TestChild )->createPrivateClosure ()));
161163 Assert::same ('Test::privateFun ' , getName (Callback::toReflection ((new TestChild )->createPrivateClosure ())));
162164
163165 Assert::same ('Test::privateFun* ' , $ test ->createPrivateClosure ()->__invoke ('* ' ));
You can’t perform that action at this time.
0 commit comments