wppaste
WordPress

WP_HTML_Processor::__construct( string $html, string|null $use_the_static_create_methods_instead = null )

Since
6.4.0
Source
wp-includes/html-api/class-wp-html-processor.php:372
Constructor.

Description

Do not use this method. Use the static creator methods instead.

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

$htmlstring
HTML to process.
$use_the_static_create_methods_insteadstring|nulloptional
This constructor should not be called manually.Default: null

Performance profile

How much work a call to WP_HTML_Processor::__construct() 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
5

Executed per call on PHP 8.5. The body compiles to 137.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksdo_action()one call below WP_HTML_Processor::__construct()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 1 distinct outcome

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

WhenInstructionsCalls it makes
always5::release_bookmark()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev137512
8.5137512
8.413751214 fewer instructions than PHP 8.3
8.3151512
8.2151512
8.1151512111 more instructions than PHP 7.4
7.44028–401

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

Source code

	public function __construct( $html, $use_the_static_create_methods_instead = null ) {		parent::__construct( $html ); 		if ( self::CONSTRUCTOR_UNLOCK_CODE !== $use_the_static_create_methods_instead ) {			_doing_it_wrong(				__METHOD__,				sprintf(					/* translators: %s: WP_HTML_Processor::create_fragment(). */					__( 'Call %s to create an HTML Processor instead of calling the constructor directly.' ),					'<code>WP_HTML_Processor::create_fragment()</code>'				),				'6.4.0'			);		} 		$this->state = new WP_HTML_Processor_State(); 		$this->state->stack_of_open_elements->set_push_handler(			function ( WP_HTML_Token $token ): void {				$is_virtual            = ! isset( $this->state->current_token ) || $this->is_tag_closer();				$same_node             = isset( $this->state->current_token ) && $token->node_name === $this->state->current_token->node_name;				$provenance            = ( ! $same_node || $is_virtual ) ? 'virtual' : 'real';				$this->element_queue[] = new WP_HTML_Stack_Event( $token, WP_HTML_Stack_Event::PUSH, $provenance ); 				$this->change_parsing_namespace( $token->integration_node_type ? 'html' : $token->namespace );			}		); 		$this->state->stack_of_open_elements->set_pop_handler(			function ( WP_HTML_Token $token ): void {				$is_virtual            = ! isset( $this->state->current_token ) || ! $this->is_tag_closer();				$same_node             = isset( $this->state->current_token ) && $token->node_name === $this->state->current_token->node_name;				$provenance            = ( ! $same_node || $is_virtual ) ? 'virtual' : 'real';				$this->element_queue[] = new WP_HTML_Stack_Event( $token, WP_HTML_Stack_Event::POP, $provenance ); 				$adjusted_current_node = $this->get_adjusted_current_node(); 				if ( $adjusted_current_node ) {					$this->change_parsing_namespace( $adjusted_current_node->integration_node_type ? 'html' : $adjusted_current_node->namespace );				} else {					$this->change_parsing_namespace( 'html' );				}			}		); 		/*		 * Create this wrapper so that it's possible to pass		 * a private method into WP_HTML_Token classes without		 * exposing it to any public API.		 */		$this->release_internal_bookmark_on_destruct = function ( string $name ): void {			parent::release_bookmark( $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 6.7.7 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.