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:983
Steps through the HTML document and stop at the next tag, if any.

Compatibility

WordPress
since 6.4.0
PHP
7.4–8.6-dev
  • 6.7.10
  • 6.8.11
  • 6.9.10
  • 7.0.7
  • 7.1.3

Present in every tracked release (6.7.10 to 7.1.3), 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–165

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
23

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

What one call costs · 49 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
always15none
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()
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()
always62–89->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_head()
always62–88->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()
always68–95->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_head()
always68–94->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()
always71–97->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_before_html()
37 further outcomes, up to 165 instructions
always74–101->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_in_table()
always74–100->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()
always77–103->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()
always80–106->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()
always83–109->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()
always86–112->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()
always89–115->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()
always92–118->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_select()
always95–121->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_in_select_in_table()
always98–124->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_template()
always101–127->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_body()
always104–130->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_in_frameset()
always107–133->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_frameset()
always110–136->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_select()
always113–140->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_after_body()
always113–139->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_select_in_table()
always116–143->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->step_after_after_frameset()
always116–142->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_template()
always119–145->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_body()
always122–148->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_in_frameset()
always124–151->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->count(), ->bail()
always125–151->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_frameset()
always128–154->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_after_body()
always131–157->get_adjusted_current_node(), ->is_tag_closer(), ->get_token_name(), ->bookmark_token(), ->has_self_closing_flag(), ->count(), ->step_after_after_frameset()
always139–165->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–16545
8.530715–16545
8.430715–16545
8.330715–16545
8.230715–165451 more instruction than PHP 8.1
8.130615–164451 fewer instruction than PHP 7.4
7.430715–16545

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 · 33

Show all 33

Used by · 23

Show all 23

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 ) {			$this->state->current_token = new WP_HTML_Token(				$this->bookmark_token(),				$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 )			)		); 		try {			if ( ! $parse_in_current_insertion_mode ) {				return $this->step_in_foreign_content();			} 			switch ( $this->state->insertion_mode ) {				case WP_HTML_Processor_State::INSERTION_MODE_INITIAL:					return $this->step_initial();

Changelog

Introduced in 6.4.0. Unchanged from 6.7.10 through 7.1.3.

  1. 6.7.10
  2. 6.8.11
  3. 6.9.10
  4. 7.0.7
  5. 7.1.3

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

About this page

Parsed data
Generated from the wordpress-develop 6.8.11 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.