From e39e744b45c769ef0566beeb3572b842b79c7585 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 23 May 2022 09:39:33 +0300 Subject: [PATCH] Fix #19384: Normalize `setBodyParams()` and `getBodyParam()` in `yii\web\Request` --- framework/CHANGELOG.md | 1 + framework/web/Request.php | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index adf431a61d..c77e5bac26 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -26,6 +26,7 @@ Yii Framework 2 Change Log - Bug #19237: Fix OCI PHP 8.1 passing `null` to trim() (longthanhtran) - Bug #19312: Fix PHP 8.1 error when passing null to `yii\helpers\BaseInflector` (WinterSilence) - Bug #19368: Fix PHP 8.1 error when `$fileMimeType` is `null` in `yii\validators\FileValidator::validateMimeType()` (bizley) +- Enh #19384: Normalize `setBodyParams()` and `getBodyParam()` in `yii\web\Request` (WinterSilence, albertborsos) - Bug #19386: Fix recursive calling `yii\helpers\BaseArrayHelper::htmlDecode()` (WinterSilence) diff --git a/framework/web/Request.php b/framework/web/Request.php index 722c31ea2a..1736e711ed 100644 --- a/framework/web/Request.php +++ b/framework/web/Request.php @@ -597,8 +597,8 @@ class Request extends \yii\base\Request /** * Sets the request body parameters. - * @param array $values the request body parameters (name-value pairs) - * @see getBodyParam() + * + * @param array|object $values the request body parameters (name-value pairs) * @see getBodyParams() */ public function setBodyParams($values) @@ -608,7 +608,9 @@ class Request extends \yii\base\Request /** * Returns the named request body parameter value. + * * If the parameter does not exist, the second parameter passed to this method will be returned. + * * @param string $name the parameter name * @param mixed $defaultValue the default parameter value if the parameter does not exist. * @return mixed the parameter value @@ -622,7 +624,7 @@ class Request extends \yii\base\Request if (is_object($params)) { // unable to use `ArrayHelper::getValue()` due to different dots in key logic and lack of exception handling try { - return $params->{$name}; + return isset($params->{$name}) ? $params->{$name} : $defaultValue; } catch (\Exception $e) { return $defaultValue; }