WP_HTML_Processor::step_in_table_body(): bool
- Since
- 6.7.0
- Source
wp-includes/html-api/class-wp-html-processor.php:3915
Description
This internal function performs the 'in table body' insertion mode logic for the generalized WP_HTML_Processor::step() function.
Compatibility
- WordPress
- since 6.7.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.
Return value
bool- Whether an element was found.
Performance profile
How much work a call to WP_HTML_Processor::step_in_table_body() 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
- Scaling
- Constant
- Instructions
- 14–73
- Plugin surface
- None
- Called by
- 2
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 158.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 10 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_HTML_Processor::step_in_table_body() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14–57 | ->get_tag(), ->is_tag_closer(), ->step() |
| always | 14–58 | ->get_tag(), ->is_tag_closer(), ->step_in_table() |
!->has_element_in_table_scope() | 20–33 | ->get_tag(), ->is_tag_closer(), ->has_element_in_table_scope(), ->step() |
| always | 25–28 | ->get_tag(), ->is_tag_closer(), ->clear_to_table_body_context(), ->insert_html_element() |
| always | 27–34 | ->get_tag(), ->is_tag_closer(), ->clear_to_table_body_context(), ->insert_virtual_node(), ->step() |
->has_element_in_table_scope() | 29–42 | ->get_tag(), ->is_tag_closer(), ->has_element_in_table_scope(), ->clear_to_table_body_context(), ->pop() |
!->has_element_in_table_scope() | 32–59 | ->get_tag(), ->is_tag_closer(), ->has_element_in_table_scope(), ->has_element_in_table_scope(), ->has_element_in_table_scope(), ->step() |
->has_element_in_table_scope() | 34–61 | ->get_tag(), ->is_tag_closer(), ->has_element_in_table_scope(), ->clear_to_table_body_context(), ->pop(), ->step() |
| always | 40–67 | ->get_tag(), ->is_tag_closer(), ->has_element_in_table_scope(), ->has_element_in_table_scope(), ->clear_to_table_body_context(), ->pop(), ->step() |
| always | 46–73 | ->get_tag(), ->is_tag_closer(), ->has_element_in_table_scope(), ->has_element_in_table_scope(), ->has_element_in_table_scope(), ->clear_to_table_body_context(), ->pop(), ->step() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 158 | 14–73 | 27 | |
| 8.5 | 158 | 14–73 | 27 | |
| 8.4 | 158 | 14–73 | 27 | |
| 8.3 | 158 | 14–73 | 27 | |
| 8.2 | 158 | 14–73 | 27 | 1 more instruction than PHP 8.1 |
| 8.1 | 157 | 14–73 | 27 | |
| 7.4 | 157 | 14–73 | 27 |
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 · 6
- WP_HTML_Processor::get_tag()Returns the uppercase name of the matched tag.
- WP_HTML_Processor::is_tag_closer()Indicates if the current tag token is a tag closer.
- WP_HTML_Processor::insert_html_element()Inserts an HTML element on the stack of open elements.
- WP_HTML_Processor::insert_virtual_node()Inserts a virtual element on the stack of open elements.
- WP_HTML_Processor::step()Steps through the HTML document and stop at the next tag, if any.
- WP_HTML_Processor::step_in_table()Parses next element in the 'in table' insertion mode.
Used by · 2
- WP_HTML_Processor::step()Steps through the HTML document and stop at the next tag, if any.
- WP_HTML_Processor::step_in_foreign_content()Parses next element in the 'in foreign content' insertion mode.
Source code
private function step_in_table_body(): bool { $tag_name = $this->get_tag(); $op_sigil = $this->is_tag_closer() ? '-' : '+'; $op = "{$op_sigil}{$tag_name}"; switch ( $op ) { /* * > A start tag whose tag name is "tr" */ case '+TR': $this->state->stack_of_open_elements->clear_to_table_body_context(); $this->insert_html_element( $this->state->current_token ); $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_ROW; return true; /* * > A start tag whose tag name is one of: "th", "td" */ case '+TH': case '+TD': // @todo Indicate a parse error once it's possible. $this->state->stack_of_open_elements->clear_to_table_body_context(); $this->insert_virtual_node( 'TR' ); $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_ROW; return $this->step( self::REPROCESS_CURRENT_NODE ); /* * > An end tag whose tag name is one of: "tbody", "tfoot", "thead" */ case '-TBODY': case '-TFOOT': case '-THEAD': if ( ! $this->state->stack_of_open_elements->has_element_in_table_scope( $tag_name ) ) { // Parse error: ignore the token. return $this->step(); } $this->state->stack_of_open_elements->clear_to_table_body_context(); $this->state->stack_of_open_elements->pop(); $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE; return true; /* * > A start tag whose tag name is one of: "caption", "col", "colgroup", "tbody", "tfoot", "thead" * > An end tag whose tag name is "table" */ case '+CAPTION': case '+COL': case '+COLGROUP': case '+TBODY': case '+TFOOT': case '+THEAD': case '-TABLE': if ( ! $this->state->stack_of_open_elements->has_element_in_table_scope( 'TBODY' ) && ! $this->state->stack_of_open_elements->has_element_in_table_scope( 'THEAD' ) && ! $this->state->stack_of_open_elements->has_element_in_table_scope( 'TFOOT' ) ) { // Parse error: ignore the token. return $this->step(); } $this->state->stack_of_open_elements->clear_to_table_body_context(); $this->state->stack_of_open_elements->pop(); $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_TABLE; return $this->step( self::REPROCESS_CURRENT_NODE ); /* * > An end tag whose tag name is one of: "body", "caption", "col", "colgroup", "html", "td", "th", "tr" */ case '-BODY': case '-CAPTION': case '-COL': case '-COLGROUP': case '-HTML': case '-TD': case '-TH': case '-TR': // Parse error: ignore the token. return $this->step(); }Changelog
Introduced in 6.7.0. Unchanged from 6.7.7 through 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.