diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php
index 7ca5191a0f162..526206f19eb2d 100644
--- a/src/wp-includes/html-api/class-wp-html-tag-processor.php
+++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php
@@ -1207,11 +1207,12 @@ public function class_list() {
$is_quirks = self::QUIRKS_MODE === $this->compat_mode;
- $at = 0;
- while ( $at < strlen( $class ) ) {
+ $at = 0;
+ $class_length = strlen( $class );
+ while ( $at < $class_length ) {
// Skip past any initial boundary characters.
$at += strspn( $class, " \t\f\r\n", $at );
- if ( $at >= strlen( $class ) ) {
+ if ( $at >= $class_length ) {
return;
}