wppaste
WordPress

WP_HTML_Processor::step( string $node_to_process = self::PROCESS_NEXT_NODE ): bool

Since
6.4.0
Source
wp-includes/html-api/class-wp-html-processor.php:1020
Steps through the HTML document and stop at the next tag, if any.

Description

This is an internal method. The relevant public methods are WP_HTML_Processor::next_tag() and WP_HTML_Processor::next_token().

Compatibility

WordPress
since 6.4.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$node_to_processstringoptional
Whether to parse the next node or reprocess the current node.Default: self::PROCESS_NEXT_NODE

Return value

bool
Whether a tag was matched.

Performance profile

How much work a call to WP_HTML_Processor::step() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
15–162

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 307.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
22

22 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 68 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_HTML_Processor::step() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always15–19none
$node_to_process === false21::next_token()
always47–74->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_foreign_content()
always53–80->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_initial()
$node_to_process === false53–67::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_foreign_content()
always56–83->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_before_html()
always59–86->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_before_head()
$node_to_process === false59–74::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_initial()
always62–89->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_head()
$node_to_process === false62–77::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_before_html()
always64–91->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_foreign_content()
always65–92->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_head_noscript()
56 further outcomes, up to 162 instructions
$node_to_process === false65–80::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_before_head()
always68–95->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_head()
$node_to_process === false68–83::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_head()
always70–97->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_initial()
always71–98->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_body()
$node_to_process === false71–86::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_head_noscript()
always73–100->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_before_html()
always74–101->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table()
$node_to_process === false74–89::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_head()
always76–103->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_before_head()
always77–104->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table_text()
$node_to_process === false77–92::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_body()
always79–106->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_head()
always80–107->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_caption()
$node_to_process === false80–95::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table()
always82–109->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_head_noscript()
always83–110->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_column_group()
$node_to_process === false83–98::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table_text()
always85–112->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_head()
always86–113->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table_body()
$node_to_process === false86–101::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_caption()
always88–115->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_body()
always89–116->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_row()
$node_to_process === false89–104::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_column_group()
always91–118->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_table()
always92–119->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_cell()
$node_to_process === false92–107::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table_body()
always94–121->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_table_text()
always95–122->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_template()
$node_to_process === false95–110::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_row()
always97–124->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_caption()
always98–125->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_body()
$node_to_process === false98–113::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_cell()
always100–127->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_column_group()
always101–128->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_frameset()
$node_to_process === false101–116::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_template()
always103–130->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_table_body()
always104–131->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_frameset()
$node_to_process === false104–118::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_body()
always106–133->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_row()
always107–134->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_after_body()
$node_to_process === false107–121::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_frameset()
always109–136->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_cell()
always110–137->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_after_frameset()
$node_to_process === false110–124::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_frameset()
always112–139->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_template()
$node_to_process === false113–127::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_after_body()
always115–142->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_body()
$node_to_process === false116–130::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_after_frameset()
always118–145->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->bail()
always118–145->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_frameset()
always121–148->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_frameset()
$node_to_process === false124–138::next_token(), ->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->bail()
always124–151->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_after_body()
always127–154->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_after_frameset()
always135–162->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->bail()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev30715–16245
8.530715–16245
8.430715–16245
8.330715–16245
8.230715–162451 more instruction than PHP 8.1
8.130615–160451 fewer instruction than PHP 7.4
7.430715–16145

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 31

Show all 31

Used by · 22

Show all 22

Source code

	public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool {		// Refuse to proceed if there was a previous error.		if ( null !== $this->last_error ) {			return false;		} 		if ( self::REPROCESS_CURRENT_NODE !== $node_to_process ) {			/*			 * Void elements still hop onto the stack of open elements even though			 * there's no corresponding closing tag. This is important for managing			 * stack-based operations such as "navigate to parent node" or checking			 * on an element's breadcrumbs.			 *			 * When moving on to the next node, therefore, if the bottom-most element			 * on the stack is a void element, it must be closed.			 */			$top_node = $this->state->stack_of_open_elements->current_node();			if ( isset( $top_node ) && ! $this->expects_closer( $top_node ) ) {				$this->state->stack_of_open_elements->pop();			}		} 		if ( self::PROCESS_NEXT_NODE === $node_to_process ) {			parent::next_token();			if ( WP_HTML_Tag_Processor::STATE_TEXT_NODE === $this->parser_state ) {				parent::subdivide_text_appropriately();			}		} 		// Finish stepping when there are no more tokens in the document.		if (			WP_HTML_Tag_Processor::STATE_INCOMPLETE_INPUT === $this->parser_state ||			WP_HTML_Tag_Processor::STATE_COMPLETE === $this->parser_state		) {			return false;		} 		$adjusted_current_node = $this->get_adjusted_current_node();		$is_closer             = $this->is_tag_closer();		$is_start_tag          = WP_HTML_Tag_Processor::STATE_MATCHED_TAG === $this->parser_state && ! $is_closer;		$token_name            = $this->get_token_name(); 		if ( self::REPROCESS_CURRENT_NODE !== $node_to_process ) {			try {				$bookmark_name = $this->bookmark_token();			} catch ( Exception $e ) {				if ( self::ERROR_EXCEEDED_MAX_BOOKMARKS === $this->last_error ) {					return false;				}				throw $e;			} 			$this->state->current_token = new WP_HTML_Token(				$bookmark_name,				$token_name,				$this->has_self_closing_flag(),				$this->release_internal_bookmark_on_destruct			);		} 		$parse_in_current_insertion_mode = (			0 === $this->state->stack_of_open_elements->count() ||			'html' === $adjusted_current_node->namespace ||			(				'math' === $adjusted_current_node->integration_node_type &&				(					( $is_start_tag && ! in_array( $token_name, array( 'MGLYPH', 'MALIGNMARK' ), true ) ) ||					'#text' === $token_name				)			) ||			(				'math' === $adjusted_current_node->namespace &&				'ANNOTATION-XML' === $adjusted_current_node->node_name &&				$is_start_tag && 'SVG' === $token_name			) ||			(				'html' === $adjusted_current_node->integration_node_type &&				( $is_start_tag || '#text' === $token_name )			)		);

Changelog

Introduced in 6.4.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/html-api/class-wp-html-processor.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.