From 5aabdd3a211b20d2a435c906d3bbefdba32a8426 Mon Sep 17 00:00:00 2001 From: Christina Reichel <123160582+chriscpty@users.noreply.github.com> Date: Mon, 18 Aug 2025 17:06:37 +0200 Subject: [PATCH] Fix #20447: Fix behavior for `yii\web\Controller::bindActionParams` around `mixed` type --- framework/CHANGELOG.md | 1 + framework/web/Controller.php | 4 ++++ tests/framework/web/ControllerTest.php | 11 +++++++++++ tests/framework/web/FakePhp7Controller.php | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 2ff00881ed..adea0cf678 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -14,6 +14,7 @@ Yii Framework 2 Change Log - Bug #20459: Fix return type in `RequestParserInterface::parse` (max-s-lab) - Bug #20475: Fix `Formatter` class `asScientific()` method for PHP `8.5` `sprintf` precision change (`6` to `0`) (terabytesoftw) - Enh #20480: Add PHPStan/Psalm annotations for `ServiceLocator::get` (max-s-lab) +- Bug #20447: Fix behavior for `yii\web\Controller::bindActionParams` around `mixed` type (chriscpty) 2.0.53 June 27, 2025 -------------------- diff --git a/framework/web/Controller.php b/framework/web/Controller.php index 3508bfe0c1..9520a1b318 100644 --- a/framework/web/Controller.php +++ b/framework/web/Controller.php @@ -208,6 +208,10 @@ class Controller extends \yii\base\Controller if ($isArray) { return [(array)$param, true]; } + $isMixed = $type->getName() === 'mixed'; + if ($isMixed) { + return [$param, true]; + } if (is_array($param)) { return [$param, false]; diff --git a/tests/framework/web/ControllerTest.php b/tests/framework/web/ControllerTest.php index aaff03f3b5..aa4e75d470 100644 --- a/tests/framework/web/ControllerTest.php +++ b/tests/framework/web/ControllerTest.php @@ -254,6 +254,17 @@ class ControllerTest extends TestCase list($foo) = $this->controller->bindActionParams($stringy, ['foo' => '']); $this->assertSame('', $foo); + // make sure mixed type works + $params = ['foo' => 100]; + $mixedParameter = new InlineAction('mixed-parameter', $this->controller, 'actionMixedParameter'); + list($foo) = $this->controller->bindActionParams($mixedParameter, $params); + $this->assertSame(100, $foo); + $params = ['foo' => 'foobar']; + $mixedParameter = new InlineAction('mixed-parameter', $this->controller, 'actionMixedParameter'); + list($foo) = $this->controller->bindActionParams($mixedParameter, $params); + $this->assertSame('foobar', $foo); + + $params = ['foo' => 'oops', 'bar' => null]; $this->expectException('yii\web\BadRequestHttpException'); $this->expectExceptionMessage('Invalid data received for parameter "foo".'); diff --git a/tests/framework/web/FakePhp7Controller.php b/tests/framework/web/FakePhp7Controller.php index 1ab5c55708..e0699f414f 100644 --- a/tests/framework/web/FakePhp7Controller.php +++ b/tests/framework/web/FakePhp7Controller.php @@ -24,4 +24,8 @@ class FakePhp7Controller extends Controller public function actionStringy(?string $foo = null) { } + + public function actionMixedParameter(mixed $foo) + { + } }