diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php
index 009019921d3..52c86d24dc4 100644
--- a/framework/helpers/BaseHtml.php
+++ b/framework/helpers/BaseHtml.php
@@ -2316,6 +2316,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 1c1c7bc0102..5b613ffd4e9 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 = [