diff --git a/lib/experimental/html/class-wp-html-tag-processor.php b/lib/experimental/html/class-wp-html-tag-processor.php
index 0d1c0756e843c..cd6ab70ae1852 100644
--- a/lib/experimental/html/class-wp-html-tag-processor.php
+++ b/lib/experimental/html/class-wp-html-tag-processor.php
@@ -761,7 +761,8 @@ private function class_name_updates_to_attributes_updates() {
$modified = false;
// Remove unwanted classes by only copying the new ones.
- while ( $at < strlen( $existing_class ) ) {
+ $existing_class_length = strlen( $existing_class );
+ while ( $at < $existing_class_length ) {
// Skip to the first non-whitespace character.
$ws_at = $at;
$ws_length = strspn( $existing_class, " \t\f\r\n", $ws_at );