Skip to content

Commit e39e744

Browse files
Fix #19384: Normalize setBodyParams() and getBodyParam() in yii\web\Request
1 parent 41f7986 commit e39e744

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

framework/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Yii Framework 2 Change Log
2626
- Bug #19237: Fix OCI PHP 8.1 passing `null` to trim() (longthanhtran)
2727
- Bug #19312: Fix PHP 8.1 error when passing null to `yii\helpers\BaseInflector` (WinterSilence)
2828
- Bug #19368: Fix PHP 8.1 error when `$fileMimeType` is `null` in `yii\validators\FileValidator::validateMimeType()` (bizley)
29+
- Enh #19384: Normalize `setBodyParams()` and `getBodyParam()` in `yii\web\Request` (WinterSilence, albertborsos)
2930
- Bug #19386: Fix recursive calling `yii\helpers\BaseArrayHelper::htmlDecode()` (WinterSilence)
3031

3132

framework/web/Request.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ public function getBodyParams()
597597

598598
/**
599599
* Sets the request body parameters.
600-
* @param array $values the request body parameters (name-value pairs)
601-
* @see getBodyParam()
600+
*
601+
* @param array|object $values the request body parameters (name-value pairs)
602602
* @see getBodyParams()
603603
*/
604604
public function setBodyParams($values)
@@ -608,7 +608,9 @@ public function setBodyParams($values)
608608

609609
/**
610610
* Returns the named request body parameter value.
611+
*
611612
* If the parameter does not exist, the second parameter passed to this method will be returned.
613+
*
612614
* @param string $name the parameter name
613615
* @param mixed $defaultValue the default parameter value if the parameter does not exist.
614616
* @return mixed the parameter value
@@ -622,7 +624,7 @@ public function getBodyParam($name, $defaultValue = null)
622624
if (is_object($params)) {
623625
// unable to use `ArrayHelper::getValue()` due to different dots in key logic and lack of exception handling
624626
try {
625-
return $params->{$name};
627+
return isset($params->{$name}) ? $params->{$name} : $defaultValue;
626628
} catch (\Exception $e) {
627629
return $defaultValue;
628630
}

0 commit comments

Comments
 (0)