Skip to content

Commit 9480f4a

Browse files
committed
fix: pass no object to invokeArgs() for static methods in ReflectionHelper
1 parent d4da78c commit 9480f4a

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎docs/changelogs/v4.8.0.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,5 +394,6 @@ Release Date: Unreleased
394394
## Bugs Fixed
395395

396396
- **Config:** Fixed a bug where instantiating an anonymous `BaseConfig` subclass threw a `ValueError` from `getenv()` on PHP 8.6.
397+
- **Testing:** Fixed a bug where `ReflectionHelper::getPrivateMethodInvoker()` passed an object when invoking a static method, which is deprecated in PHP 8.6.
397398

398399
See the repo's [CHANGELOG.md](https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md) for a complete list of bugs fixed.

‎system/Test/ReflectionHelper.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ trait ReflectionHelper
3838
public static function getPrivateMethodInvoker($obj, $method)
3939
{
4040
$refMethod = new ReflectionMethod($obj, $method);
41-
$obj = (gettype($obj) === 'object') ? $obj : null;
41+
$object = gettype($obj) === 'object' && ! $refMethod->isStatic() ? $obj : null;
4242

43-
return static fn (...$args): mixed => $refMethod->invokeArgs($obj, $args);
43+
return static fn (...$args): mixed => $refMethod->invokeArgs($object, $args);
4444
}
4545

4646
/**

‎tests/system/Test/ReflectionHelperTest.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ public function testGetPrivateMethodInvokerWithObject(): void
9191
);
9292
}
9393

94+
public function testGetPrivateMethodInvokerWithStaticMethodOnObject(): void
95+
{
96+
$method = self::getPrivateMethodInvoker(
97+
new TestForReflectionHelper(),
98+
'privateStaticMethod',
99+
);
100+
$this->assertSame(
101+
'private_static param1param2',
102+
$method('param1', 'param2'),
103+
);
104+
}
105+
94106
public function testGetPrivateMethodInvokerWithStatic(): void
95107
{
96108
$method = self::getPrivateMethodInvoker(

0 commit comments

Comments
 (0)