Skip to content

Commit ac2b0f9

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

3 files changed

Lines changed: 34 additions & 21 deletions

File tree

‎docs/changelogs/v4.8.0.md‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ Release Date: Unreleased
6565

6666
- **CLI:** The `Console::run()` method now accepts an optional `array $tokens` parameter. This allows you to pass an array of command tokens directly to the console runner, which is useful for testing or programmatically running commands. If not provided, it will default to using the global `$argv`.
6767

68-
- **CodeIgniter:** The deprecated parameters in methods have been removed:
69-
- `CodeIgniter\CodeIgniter::handleRequest()` no longer accepts the deprecated `$cacheConfig` and `$returnResponse` parameters.
68+
- **CodeIgniter:** The deprecated parameters in methods have been removed:
69+
- `CodeIgniter\CodeIgniter::handleRequest()` no longer accepts the deprecated `$cacheConfig` and `$returnResponse` parameters.
7070
- `$cacheConfig` is no longer used and is now hard deprecated. A deprecation notice will be triggered if this is passed to the method.
7171
- `$returnResponse` has been removed, since it was already deprecated and unused.
7272
- The updated method signature is now `handleRequest(?RouteCollectionInterface $routes, ?Cache $cacheConfig = null)`.
@@ -75,7 +75,7 @@ Release Date: Unreleased
7575

7676
- **Config:** `CodeIgniter\Config\Services::request()` no longer accepts any parameter.
7777

78-
- **Database:** The following methods have had their signatures updated to remove deprecated parameters:
78+
- **Database:** The following methods have had their signatures updated to remove deprecated parameters:
7979
- `CodeIgniter\Database\Forge::_createTable()` no longer accepts the deprecated `$ifNotExists` parameter. The method signature is now `_createTable(string $table, array $attributes)`.
8080

8181
- **HTTP:** `CodeIgniter\HTTP\OutgoingRequest::__construct()` now requires the `$uri` parameter, which was previously `?URI $uri = null`. Passing `null` only worked when a `Host` header was supplied in the same call, since the constructor otherwise dereferences the URI to set that header. Consequently `OutgoingRequest::getUri()` now returns `URI` instead of `URI|null`, matching `OutgoingRequestInterface`. See [Upgrading from 4.7.x to 4.8.0](../installation/upgrade_480.md) for the migration.
@@ -86,41 +86,41 @@ Release Date: Unreleased
8686

8787
### Property Scope Changes
8888

89-
- **HTTP:** The following properties have changed their scope (visibility):
89+
- **HTTP:** The following properties have changed their scope (visibility):
9090
- `CodeIgniter\HTTP\RequestTrait::$ipAddress` is now private (previously protected).
9191

9292
### Method Scope Changes
9393

9494
- **CLI:** `CodeIgniter\CLI\Commands::getCommandAlternatives()` is now public (previously protected).
9595

96-
- **HTTP:** The following methods have changed their scope (visibility):
96+
- **HTTP:** The following methods have changed their scope (visibility):
9797
- `CodeIgniter\HTTP\URI::setUri()` is now private (previously public).
9898
- `CodeIgniter\HTTP\URI::refreshPath()` is now protected (previously public).
9999
- `CodeIgniter\HTTP\SiteURI::refreshPath()` is now protected (previously public).
100100

101101
### Removed Deprecated Items
102102

103-
- **Autoloader:** Removed the following deprecated methods:
103+
- **Autoloader:** Removed the following deprecated methods:
104104
- `CodeIgniter\Autoloader\Autoloader::sanitizeFileName()`
105105
- `CodeIgniter\Autoloader\Autoloader::discoverComposerNamespaces()`
106106

107107
- **Bootstrap:** The deprecated **system/bootstrap.php** file has been removed.
108108

109-
- **Cache:** Removed the following deprecated methods and constant:
109+
- **Cache:** Removed the following deprecated methods and constant:
110110
- `CodeIgniter\Cache\Handlers\BaseHandler::RESERVED_CHARACTERS` (deprecated since v4.1.5)
111111
- `CodeIgniter\Cache\Handlers\FileHandler::writeFile()` (deprecated since v4.6.0)
112112
- `CodeIgniter\Cache\Handlers\FileHandler::deleteFile()` (deprecated since v4.6.0)
113113
- `CodeIgniter\Cache\Handlers\FileHandler::getDirFileInfo()` (deprecated since v4.6.0)
114114
- `CodeIgniter\Cache\Handlers\FileHandler::getFileInfo()` (deprecated since v4.6.0)
115115

116-
- **CLI:** Removed the following deprecated properties and methods:
116+
- **CLI:** Removed the following deprecated properties and methods:
117117
- `CodeIgniter\CLI\BaseCommand::getPad()`
118118
- `CodeIgniter\CLI\CLI::$readline_support`
119119
- `CodeIgniter\CLI\CLI::$wait_msg`
120120
- `CodeIgniter\CLI\CLI::isWindows()`
121121
- `CodeIgniter\CLI\GeneratorTrait::execute()`
122122

123-
- **CodeIgniter:** Removed the following deprecated properties and methods:
123+
- **CodeIgniter:** Removed the following deprecated properties and methods:
124124
- `CodeIgniter\CodeIgniter::$cacheTTL`
125125
- `CodeIgniter\CodeIgniter::$returnResponse`
126126
- `CodeIgniter\CodeIgniter::initializeKint()`
@@ -136,10 +136,10 @@ Release Date: Unreleased
136136
- `CodeIgniter\CodeIgniter::callExit()`
137137
- `CodeIgniter\Test\MockCodeIgniter::callExit()`
138138

139-
- **Config:** Removed the following deprecated property:
139+
- **Config:** Removed the following deprecated property:
140140
- `CodeIgniter\Config\BaseService::$services` (deprecated since v4.5.0)
141141

142-
- **Database:** Removed the following deprecated properties and methods:
142+
- **Database:** Removed the following deprecated properties and methods:
143143
- `CodeIgniter\Database\BaseBuilder::setInsertBatch()`
144144
- `CodeIgniter\Database\BaseBuilder::setUpdateBatch()`
145145
- `CodeIgniter\Database\BaseBuilder::cleanClone()`
@@ -151,7 +151,7 @@ Release Date: Unreleased
151151
- `CodeIgniter\Database\OCI8\Forge::getError()`
152152
- `CodeIgniter\Database\SQLSRV\Forge::$createTableIfStr`
153153

154-
- **Debug:** Removed the following deprecated properties and methods:
154+
- **Debug:** Removed the following deprecated properties and methods:
155155
- `CodeIgniter\Debug\Toolbar\Collectors\BaseCollector::cleanPath()` (deprecated since v4.2.0)
156156
- `CodeIgniter\Debug\Exceptions::$ob_level` (deprecated since v4.4.0)
157157
- `CodeIgniter\Debug\Exceptions::$viewPath` (deprecated since v4.4.0)
@@ -164,25 +164,25 @@ Release Date: Unreleased
164164
- `CodeIgniter\Debug\Exceptions::describeMemory()` (deprecated since v4.4.0)
165165
- `CodeIgniter\Debug\Exceptions::highlightFile()` (deprecated since v4.4.0)
166166

167-
- **Exceptions:** Removed the following static constructors of `FrameworkException` and its child classes:
167+
- **Exceptions:** Removed the following static constructors of `FrameworkException` and its child classes:
168168
- `CodeIgniter\Exceptions\DownloadException::forCannotSetCache()`
169169
- `CodeIgniter\Exceptions\FrameworkException::forMissingExtension()`
170170
- `CodeIgniter\Honeypot\Exceptions\HoneypotException::forNoHiddenValue()`
171171
- `CodeIgniter\HTTP\Exceptions\HTTPException::forInvalidSameSiteSetting()`
172172
- `CodeIgniter\Security\Exceptions\SecurityException::forInvalidSameSite()`
173173
- `CodeIgniter\Session\Exceptions\SessionException::forInvalidSameSiteSetting()`
174174

175-
- **Files:** Removed the following deprecated method:
175+
- **Files:** Removed the following deprecated method:
176176
- `CodeIgniter\Files\File::getSizeByUnit()` (deprecated since v4.6.0)
177177

178-
- **Filters:** Removed the following deprecated properties and methods:
178+
- **Filters:** Removed the following deprecated properties and methods:
179179
- `CodeIgniter\Filters\Filters::$arguments` (deprecated since v4.6.0)
180180
- `CodeIgniter\Filters\Filters::$argumentsClass` (deprecated since v4.6.0)
181181
- `CodeIgniter\Filters\Filters::getArguments()` (deprecated since v4.6.0)
182182
- `CodeIgniter\Filters\Filters::discoverFilters()` and the auto-discovery of **Config/Filters.php** files (deprecated since v4.4.2)
183183
- `CodeIgniter\Filters\Filters::$modules` and the `$modules` constructor parameter, which were only used by the auto-discovery
184184

185-
- **HTTP:** Removed the following deprecated properties and methods:
185+
- **HTTP:** Removed the following deprecated properties and methods:
186186
- `CodeIgniter\HTTP\Message::getHeaders()` (deprecated since v4.0.5)
187187
- `CodeIgniter\HTTP\Message::getHeader()` (deprecated since v4.0.5)
188188
- `CodeIgniter\HTTP\RequestTrait::getEnv()` (deprecated since v4.4.4)
@@ -195,7 +195,7 @@ Release Date: Unreleased
195195
- `CodeIgniter\HTTP\SiteURI::setBaseURL()` (deprecated since v4.4.0)
196196
- `CodeIgniter\HTTP\SiteURI::setURI()` (deprecated since v4.4.0)
197197

198-
- **Security:** Removed the following deprecated properties and methods:
198+
- **Security:** Removed the following deprecated properties and methods:
199199
- `CodeIgniter\Security\SecurityInterface::sanitizeFilename()` (deprecated since v4.6.2)
200200
- `CodeIgniter\Security\Security::sanitizeFilename()` (deprecated since v4.6.2)
201201
- `CodeIgniter\Security\Security::$csrfProtection` (deprecated since v4.4.0)
@@ -356,15 +356,15 @@ Release Date: Unreleased
356356

357357
## Message Changes
358358

359-
- Added new language keys:
359+
- Added new language keys:
360360
- `Cache.unsupportedLockStore` (`CacheException::forUnsupportedLockStore()`)
361361
- `CLI.commandAlias` and `CLI.helpAliases` (command alias rendering in `list` and `help`)
362362
- `CLI.altCommandNone`, `CLI.altCommandRun`, and `CLI.altCommandSelect` (correcting a mistyped command)
363363
- `CLI.generator.invalidCommandType` (`make:command` rejecting an invalid `--type`)
364364
- `CLI.generator.invalidReturnType` (`make:model` rejecting an invalid `--return`)
365365
- `Commands.invalidCommandAlias`, `Commands.commandAliasSameAsName`, `Commands.duplicateCommandAlias`, `Commands.aliasClashesWithCommandName`, and `Commands.aliasClashesWithAlias` (command alias validation)
366366

367-
- Removed deprecated language keys tied to removed exception constructors:
367+
- Removed deprecated language keys tied to removed exception constructors:
368368
- `Core.missingExtension` (`FrameworkException::forMissingExtension()`)
369369
- `HTTP.cannotSetCache` (`DownloadException::forCannotSetCache()`)
370370
- `HTTP.disallowedAction`
@@ -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)