mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
php-8.0-compat: fix "Error: Unknown named parameter $subject"
PHP 8 added support for named parameters however will throw an error when a named parameter, which does not exist, will be called/appears. In this case the code uses `array_filter(compact('subject))` to conveniently prepend `$subject` to the callback, if it's non-null. It's then combined with `$params` but mixing a hash wih a sequential array and then end result is `['subject' => …, ]` which then triggers this TypeError in PHP 8. The solution applies `array_values()` on above array as to remove the keys and then the error disappears. With this change, our internal test suite (2k tests) is green on both PHP8 and PHP7.4, aka this change is expecte to be backwards compatible.
This commit is contained in:
parent
b07bba4d4f
commit
d201312a0e
1 changed files with 1 additions and 1 deletions
|
@ -126,7 +126,7 @@ abstract class ObjectCollection {
|
||||||
}
|
}
|
||||||
$result = null;
|
$result = null;
|
||||||
foreach ($list as $name) {
|
foreach ($list as $name) {
|
||||||
$result = call_user_func_array(array($this->_loaded[$name], $callback), array_filter(compact('subject')) + $params);
|
$result = call_user_func_array(array($this->_loaded[$name], $callback), array_values(array_filter(compact('subject')) + $params));
|
||||||
if ($options['collectReturn'] === true) {
|
if ($options['collectReturn'] === true) {
|
||||||
$collected[] = $result;
|
$collected[] = $result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue