WP_HTML_Processor::step_in_cell(): bool
- Since
- 6.7.0
- Source
wp-includes/html-api/class-wp-html-processor.php:4130
Description
This internal function performs the 'in cell' 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_cell() 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–67
- 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 121.
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 · 6 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_cell() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14–47 | ->get_tag(), ->is_tag_closer(), ->step() |
| always | 14–58 | ->get_tag(), ->is_tag_closer(), ->step_in_body() |
| always | 18–41 | ->get_tag(), ->is_tag_closer(), ->close_cell(), ->step() |
!->has_element_in_table_scope() | 20–63 | ->get_tag(), ->is_tag_closer(), ->has_element_in_table_scope(), ->step() |
->has_element_in_table_scope() | 24–67 | ->get_tag(), ->is_tag_closer(), ->has_element_in_table_scope(), ->close_cell(), ->step() |
->has_element_in_table_scope() | 38–43 | ->get_tag(), ->is_tag_closer(), ->has_element_in_table_scope(), ->generate_implied_end_tags(), ->current_node_is(), ->pop_until(), ->clear_up_to_last_marker() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 121 | 14–67 | 25 | |
| 8.5 | 121 | 14–67 | 25 | |
| 8.4 | 121 | 14–67 | 25 | |
| 8.3 | 121 | 14–67 | 25 | |
| 8.2 | 121 | 14–67 | 25 | 1 more instruction than PHP 8.1 |
| 8.1 | 120 | 14–81 | 25 | 1 more instruction than PHP 7.4 |
| 7.4 | 119 | 14–80 | 25 |
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::step()Steps through the HTML document and stop at the next tag, if any.
- WP_HTML_Processor::generate_implied_end_tags()Closes elements that have implied end tags.
- WP_HTML_Processor::close_cell()Runs the "close the cell" algorithm.
- WP_HTML_Processor::step_in_body()Parses next element in the 'in body' 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_cell(): bool { $tag_name = $this->get_tag(); $op_sigil = $this->is_tag_closer() ? '-' : '+'; $op = "{$op_sigil}{$tag_name}"; switch ( $op ) { /* * > An end tag whose tag name is one of: "td", "th" */ case '-TD': case '-TH': if ( ! $this->state->stack_of_open_elements->has_element_in_table_scope( $tag_name ) ) { // Parse error: ignore the token. return $this->step(); } $this->generate_implied_end_tags(); /* * @todo This needs to check if the current node is an HTML element, meaning that * when SVG and MathML support is added, this needs to differentiate between an * HTML element of the given name, such as `<center>`, and a foreign element of * the same given name. */ if ( ! $this->state->stack_of_open_elements->current_node_is( $tag_name ) ) { // @todo Indicate a parse error once it's possible. } $this->state->stack_of_open_elements->pop_until( $tag_name ); $this->state->active_formatting_elements->clear_up_to_last_marker(); $this->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_ROW; return true; /* * > A start tag whose tag name is one of: "caption", "col", "colgroup", "tbody", "td", * > "tfoot", "th", "thead", "tr" */ case '+CAPTION': case '+COL': case '+COLGROUP': case '+TBODY': case '+TD': case '+TFOOT': case '+TH': case '+THEAD': case '+TR': /* * > Assert: The stack of open elements has a td or th element in table scope. * * Nothing to do here, except to verify in tests that this never appears. */ $this->close_cell(); return $this->step( self::REPROCESS_CURRENT_NODE ); /* * > An end tag whose tag name is one of: "body", "caption", "col", "colgroup", "html" */ case '-BODY': case '-CAPTION': case '-COL': case '-COLGROUP': case '-HTML': // Parse error: ignore the token. return $this->step(); /* * > An end tag whose tag name is one of: "table", "tbody", "tfoot", "thead", "tr" */ case '-TABLE': case '-TBODY': case '-TFOOT': case '-THEAD': case '-TR': if ( ! $this->state->stack_of_open_elements->has_element_in_table_scope( $tag_name ) ) { // Parse error: ignore the token. return $this->step(); } $this->close_cell(); return $this->step( self::REPROCESS_CURRENT_NODE );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.