WP_HTML_Processor::step_in_table(): bool
- Since
- 6.7.0
- Source
wp-includes/html-api/class-wp-html-processor.php:3441
Description
This internal function performs the 'in table' 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() 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
- 16–111
- Plugin surface
- None
- Called by
- 4
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 330.
Nothing here hands control to plugin code.
4 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 38 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() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$token_type !== "#tag" | 16–72 | ->get_token_name(), ->get_token_type(), ->step() |
$token_type !== "#tag" | 16–80 | ->get_token_name(), ->get_token_type(), ->step_in_head() |
$token_type !== "#tag" | 17–86 | ->get_token_name(), ->get_token_type(), ->bail() |
$token_type !== "#tag" | 19–29 | ->get_token_name(), ->get_token_type(), ->insert_html_element() |
$token_type === "#tag" | 21–78 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->step() |
$token_type === "#tag" | 21–86 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->step_in_head() |
$token_type !== "#tag" && !->has_element_in_table_scope() | 22–56 | ->get_token_name(), ->get_token_type(), ->has_element_in_table_scope(), ->step() |
$token_type !== "#tag" | 22–93 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->step() |
$token_type === "#tag" | 22–92 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->bail() |
$token_type !== "#tag" && !is_string($type_attribute) | 23–89 | ->get_token_name(), ->get_token_type(), ->get_attribute(), ->bail() |
$token_type === "#tag" | 24–35 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->insert_html_element() |
$token_type !== "#tag" | 26–41 | ->get_token_name(), ->get_token_type(), ->current_node(), ->bail() |
26 further outcomes, up to 59 instructions
$token_type !== "#tag" && ->has_element_in_table_scope() | 26–60 | ->get_token_name(), ->get_token_type(), ->has_element_in_table_scope(), ->pop_until(), ->reset_insertion_mode_appropriately() |
$token_type !== "#tag" | 27–51 | ->get_token_name(), ->get_token_type(), ->clear_to_table_context(), ->insert_html_element() |
$token_type === "#tag" && !->has_element_in_table_scope() | 27–62 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->has_element_in_table_scope(), ->step() |
$token_type === "#tag" | 27–99 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->has_element_in_scope(), ->step() |
$token_type !== "#tag" && is_string($type_attribute) | 28–94 | ->get_token_name(), ->get_token_type(), ->get_attribute(), strtolower(), ->bail() |
$token_type === "#tag" && !is_string($type_attribute) | 28–95 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->get_attribute(), ->bail() |
$token_type !== "#tag" | 29–59 | ->get_token_name(), ->get_token_type(), ->clear_to_table_context(), ->insert_virtual_node(), ->step() |
$token_type !== "#tag" && is_string($type_attribute) | 30–96 | ->get_token_name(), ->get_token_type(), ->get_attribute(), strtolower(), ->insert_html_element() |
$token_type !== "#tag" | 31–44 | ->get_token_name(), ->get_token_type(), ->current_node(), ->step() |
$token_type !== "#tag" | 31–45 | ->get_token_name(), ->get_token_type(), ->clear_to_table_context(), ->insert_marker(), ->insert_html_element() |
$token_type === "#tag" | 31–47 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->current_node(), ->bail() |
$token_type !== "#tag" && ->has_element_in_table_scope() | 31–63 | ->get_token_name(), ->get_token_type(), ->has_element_in_table_scope(), ->pop_until(), ->reset_insertion_mode_appropriately(), ->step() |
$token_type === "#tag" && ->has_element_in_table_scope() | 31–66 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->has_element_in_table_scope(), ->pop_until(), ->reset_insertion_mode_appropriately() |
$token_type === "#tag" | 32–57 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->clear_to_table_context(), ->insert_html_element() |
$token_type === "#tag" && is_string($type_attribute) | 33–100 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->get_attribute(), strtolower(), ->bail() |
$token_type === "#tag" | 34–65 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->clear_to_table_context(), ->insert_virtual_node(), ->step() |
$token_type === "#tag" && is_string($type_attribute) | 35–102 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->get_attribute(), strtolower(), ->insert_html_element() |
$token_type === "#tag" | 36–50 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->current_node(), ->step() |
$token_type === "#tag" | 36–51 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->clear_to_table_context(), ->insert_marker(), ->insert_html_element() |
$token_type === "#tag" && ->has_element_in_table_scope() | 36–69 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->has_element_in_table_scope(), ->pop_until(), ->reset_insertion_mode_appropriately(), ->step() |
$token_type !== "#tag" && !->has_element_in_scope() && !isset($value) | 37–105 | ->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->insert_html_element(), ->pop() |
$token_type !== "#tag" | 38–51 | ->get_token_name(), ->get_token_type(), ->current_node(), ->insert_html_element() |
$token_type !== "#tag" | 40–53 | ->get_token_name(), ->get_token_type(), ->current_node(), ->bail(), ->bail() |
$token_type === "#tag" && !->has_element_in_scope() && !isset($value) | 42–111 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->has_element_in_scope(), ->insert_html_element(), ->pop() |
$token_type === "#tag" | 43–57 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->current_node(), ->insert_html_element() |
$token_type === "#tag" | 45–59 | ->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->current_node(), ->bail(), ->bail() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 330 | 16–111 | 53 | |
| 8.5 | 330 | 16–111 | 53 | |
| 8.4 | 330 | 16–111 | 53 | |
| 8.3 | 330 | 16–111 | 53 | |
| 8.2 | 330 | 16–111 | 53 | 1 more instruction than PHP 8.1 |
| 8.1 | 329 | 16–125 | 53 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 330 | 16–126 | 53 |
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 · 10
- WP_HTML_Processor::get_token_name()Returns the node name represented by the token.
- WP_HTML_Processor::get_token_type()Indicates the kind of matched token, if any.
- WP_HTML_Tag_Processor::is_tag_closer()Indicates if the current tag token is a tag closer.
- WP_HTML_Processor::step()Steps through the HTML document and stop at the next tag, if any.
- WP_HTML_Processor::insert_html_element()Inserts an HTML element on the stack of open elements.
- WP_HTML_Processor::bail()Stops the parser and terminates its execution when encountering unsupported markup.
- WP_HTML_Processor::insert_virtual_node()Inserts a virtual element on the stack of open elements.
- WP_HTML_Processor::reset_insertion_mode_appropriately()Runs the reset the insertion mode appropriately algorithm.
- WP_HTML_Processor::step_in_head()Parses next element in the 'in head' insertion mode.
- WP_HTML_Processor::get_attribute()Returns the value of a requested attribute from a matched tag opener if that attribute exists.
Used by · 4
- 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.
- WP_HTML_Processor::step_in_row()Parses next element in the 'in row' insertion mode.
- WP_HTML_Processor::step_in_table_body()Parses next element in the 'in table body' insertion mode.
Source code
private function step_in_table(): bool { $token_name = $this->get_token_name(); $token_type = $this->get_token_type(); $op_sigil = '#tag' === $token_type ? ( parent::is_tag_closer() ? '-' : '+' ) : ''; $op = "{$op_sigil}{$token_name}"; switch ( $op ) { /* * > A character token, if the current node is table, * > tbody, template, tfoot, thead, or tr element */ case '#text': $current_node = $this->state->stack_of_open_elements->current_node(); $current_node_name = $current_node ? $current_node->node_name : null; if ( $current_node_name && ( 'TABLE' === $current_node_name || 'TBODY' === $current_node_name || 'TEMPLATE' === $current_node_name || 'TFOOT' === $current_node_name || 'THEAD' === $current_node_name || 'TR' === $current_node_name ) ) { /* * If the text is empty after processing HTML entities and stripping * U+0000 NULL bytes then ignore the token. */ if ( parent::TEXT_IS_NULL_SEQUENCE === $this->text_node_classification ) { return $this->step(); } /* * This follows the rules for "in table text" insertion mode. * * Whitespace-only text nodes are inserted in-place. Otherwise * foster parenting is enabled and the nodes would be * inserted out-of-place. * * > If any of the tokens in the pending table character tokens * > list are character tokens that are not ASCII whitespace, * > then this is a parse error: reprocess the character tokens * > in the pending table character tokens list using the rules * > given in the "anything else" entry in the "in table" * > insertion mode. * > * > Otherwise, insert the characters given by the pending table * > character tokens list. * * @see https://html.spec.whatwg.org/#parsing-main-intabletext */ if ( parent::TEXT_IS_WHITESPACE === $this->text_node_classification ) { $this->insert_html_element( $this->state->current_token ); return true; } // Non-whitespace would trigger fostering, unsupported at this time. $this->bail( 'Foster parenting is not supported.' ); break; } break; /* * > A comment token * > A processing instruction token */ case '#comment': case '#funky-comment': case '#presumptuous-tag': case '#processing-instruction': $this->insert_html_element( $this->state->current_token ); return true; /* * > A DOCTYPE token */ case 'html': // 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.