WP_HTML_Processor::next_visitable_token(): bool
- Since
- 6.7.2
- Source
wp-includes/html-api/class-wp-html-processor.php:804
Description
This doesn't currently have a way to represent non-tags and doesn't process semantic rules for text nodes. For access to the raw tokens consider using WP_HTML_Tag_Processor instead.
Note that this method may call itself recursively. This is why it is not implemented as WP_HTML_Processor::next_token(), which instead calls this method similarly to how WP_HTML_Tag_Processor::next_token() calls the WP_HTML_Tag_Processor::base_class_next_token() method.
Compatibility
- WordPress
- since 6.7.2
- 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
Performance profile
How much work a call to WP_HTML_Processor::next_visitable_token() 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
- Light
- Scaling
- Scales with input
- Instructions
- 5–46
- Plugin surface
- None
- Called by
- 2
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 72.
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 · 21 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_HTML_Processor::next_visitable_token() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
isset($value) | 5 | none |
empty($value) && !->step() | 12 | ->step() |
!isset($value) && empty($value) && ->step() | 12 | ->step(), ->next_visitable_token() |
!isset($value) && !->pop() | 24 | array_shift(), ->pop() |
!isset($value) && !empty($value) && !->pop() | 24 | array_shift(), ->pop(), ->next_visitable_token() |
!empty($value) | 26 | array_shift(), ->next_visitable_token() |
!isset($value) && empty($value) && !->step() && !->pop() | 29 | ->step(), array_shift(), ->pop() |
!isset($value) && !->step() && !->pop() | 29 | ->step(), array_shift(), ->pop(), ->next_visitable_token() |
!empty($value) | 31 | array_shift(), array_pop() |
empty($value) && !->step() | 31 | ->step(), array_shift(), ->next_visitable_token() |
!empty($value) | 32 | array_shift() |
empty($value) && !->step() | 36 | ->step(), array_shift(), array_pop() |
9 further outcomes, up to 46 instructions
empty($value) && !->step() | 37 | ->step(), array_shift() |
!empty($value) && ->expects_closer() | 38 | array_shift(), array_pop(), ->expects_closer() |
!empty($value) && ->expects_closer() | 39 | array_shift(), ->expects_closer() |
!empty($value) && !->expects_closer() | 40 | array_shift(), array_pop(), ->expects_closer(), ->next_visitable_token() |
!empty($value) && !->expects_closer() | 41 | array_shift(), ->expects_closer(), ->next_visitable_token() |
empty($value) && !->step() && ->expects_closer() | 43 | ->step(), array_shift(), array_pop(), ->expects_closer() |
empty($value) && !->step() && ->expects_closer() | 44 | ->step(), array_shift(), ->expects_closer() |
empty($value) && !->step() && !->expects_closer() | 45 | ->step(), array_shift(), array_pop(), ->expects_closer(), ->next_visitable_token() |
empty($value) && !->step() && !->expects_closer() | 46 | ->step(), array_shift(), ->expects_closer(), ->next_visitable_token() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 72 | 5–46 | 11 | |
| 8.5 | 72 | 5–46 | 11 | 5 fewer instructions than PHP 8.4 |
| 8.4 | 77 | 5–47 | 11 | |
| 8.3 | 77 | 5–47 | 11 | |
| 8.2 | 77 | 5–47 | 11 | 5 more instructions than PHP 8.1 |
| 8.1 | 72 | 5–46 | 11 | 5 fewer instructions than PHP 7.4 |
| 7.4 | 77 | 5–47 | 11 |
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 · 3
- WP_HTML_Processor::step()Steps through the HTML document and stop at the next tag, if any.
- WP_HTML_Processor::next_visitable_token()Ensures internal accounting is maintained for HTML semantic rules while the underlying Tag Processor class is seeking to a bookmark.
- WP_HTML_Processor::expects_closer()Indicates if the currently-matched node expects a closing token, or if it will self-close on the next step.
Used by · 2
- WP_HTML_Processor::next_token()Finds the next token in the HTML document.
- WP_HTML_Processor::next_visitable_token()Ensures internal accounting is maintained for HTML semantic rules while the underlying Tag Processor class is seeking to a bookmark.
Source code
private function next_visitable_token(): bool { $this->current_element = null; if ( isset( $this->last_error ) ) { return false; } /* * Prime the events if there are none. * * @todo In some cases, probably related to the adoption agency * algorithm, this call to step() doesn't create any new * events. Calling it again creates them. Figure out why * this is and if it's inherent or if it's a bug. Looping * until there are events or until there are no more * tokens works in the meantime and isn't obviously wrong. */ if ( empty( $this->element_queue ) ) { if ( $this->step() ) { return $this->next_visitable_token(); } if ( isset( $this->last_error ) ) { return false; } } // Process the next event on the queue. $this->current_element = array_shift( $this->element_queue ); if ( ! isset( $this->current_element ) ) { // There are no tokens left, so close all remaining open elements. while ( $this->state->stack_of_open_elements->pop() ) { continue; } return empty( $this->element_queue ) ? false : $this->next_visitable_token(); } $is_pop = WP_HTML_Stack_Event::POP === $this->current_element->operation; /* * The root node only exists in the fragment parser, and closing it * indicates that the parse is complete. Stop before popping it from * the breadcrumbs. */ if ( 'root-node' === $this->current_element->token->bookmark_name ) { return $this->next_visitable_token(); } // Adjust the breadcrumbs for this event. if ( $is_pop ) { array_pop( $this->breadcrumbs ); } else { $this->breadcrumbs[] = $this->current_element->token->node_name; } // Avoid sending close events for elements which don't expect a closing. if ( $is_pop && ! $this->expects_closer( $this->current_element->token ) ) { return $this->next_visitable_token(); } return true; }Changelog
Introduced in 6.7.2. 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.