diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php
index ff81df22752..bdb7b189ca9 100644
--- a/framework/helpers/BaseHtml.php
+++ b/framework/helpers/BaseHtml.php
@@ -2311,6 +2311,12 @@ public static function getAttributeValue($model, $attribute)
$value = $value->getPrimaryKey(false);
return is_array($value) ? json_encode($value) : $value;
+ } elseif (version_compare(PHP_VERSION, '8.1.0') >= 0) {
+ if ($value instanceof \BackedEnum) {
+ $value = $value->value;
+ } elseif ($value instanceof \UnitEnum) {
+ $value = $value->name;
+ }
}
return $value;
diff --git a/framework/validators/RangeValidator.php b/framework/validators/RangeValidator.php
index e58ea601096..8c3a7184f51 100644
--- a/framework/validators/RangeValidator.php
+++ b/framework/validators/RangeValidator.php
@@ -124,6 +124,13 @@ public function getClientOptions($model, $attribute)
{
$range = [];
foreach ($this->range as $value) {
+ if (version_compare(PHP_VERSION, '8.1.0') >= 0) {
+ if ($value instanceof \BackedEnum) {
+ $value = $value->value;
+ } elseif ($value instanceof \UnitEnum) {
+ $value = $value->name;
+ }
+ }
$range[] = (string) $value;
}
$options = [