diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php
index b2a597b938495..b4c590ef5141a 100644
--- a/src/wp-includes/html-api/class-wp-html-processor.php
+++ b/src/wp-includes/html-api/class-wp-html-processor.php
@@ -5431,14 +5431,20 @@ public function has_class( $wanted_class ): ?bool {
*
* This generator function is designed to be used inside a "foreach" loop.
*
- * Example:
- *
- * $p = WP_HTML_Processor::create_fragment( "
" );
- * $p->next_tag();
- * foreach ( $p->class_list() as $class_name ) {
- * echo "{$class_name} ";
- * }
- * // Outputs: "free
lang-en "
+ * ```php interactive
+ * " );
+ * $p->next_tag();
+ * foreach ( $p->class_list() as $class_name ) {
+ * var_dump( $class_name );
+ * }
+ * ```
+ * ```expected-output
+ * string(4) "free"
+ * string(5) ""
+ * string(7) "lang-en"
+ * ```
*
* @since 6.6.0 Subclassed for the HTML Processor.
*/
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 5745207f38fc4..41788ba102a67 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
@@ -1178,14 +1178,20 @@ public function paused_at_incomplete_token(): bool {
*
* This generator function is designed to be used inside a "foreach" loop.
*
- * Example:
- *
- * $p = new WP_HTML_Tag_Processor( "" );
- * $p->next_tag();
- * foreach ( $p->class_list() as $class_name ) {
- * echo "{$class_name} ";
- * }
- * // Outputs: "free lang-en "
+ * ```php interactive
+ * " );
+ * $p->next_tag();
+ * foreach ( $p->class_list() as $class_name ) {
+ * var_dump( $class_name );
+ * }
+ * ```
+ * ```expected-output
+ * string(4) "free"
+ * string(5) ""
+ * string(7) "lang-en"
+ * ```
*
* @since 6.4.0
*