WP_HTML_Processor::expects_closer( WP_HTML_Token|null $node = null ): bool|null
- Since
- 6.6.0
- Source
wp-includes/html-api/class-wp-html-processor.php:978
Description
Most HTML elements expect a closer, such as a P element or a DIV element. Others, like an IMG element, are void and don't have a closing tag. Special elements, such as SCRIPT and STYLE, are treated just like void tags. Text nodes and self-closing foreign content will also act just like a void tag, immediately closing as soon as the processor advances to the next token.
Compatibility
- WordPress
- since 6.6.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
$nodeWP_HTML_Token|nulloptional- Node to examine, if provided.
Default is to examine current node.Default:null
Return value
bool|null- Whether to expect a closer for the currently-matched node, or
nullif not matched on any token.
Performance profile
How much work a call to WP_HTML_Processor::expects_closer() 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
- 7–41
- 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 42.
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 · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_HTML_Processor::expects_closer() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$node | 7–28 | none |
$node | 10–31 | ->get_token_name() |
isset($token_name) | 20–31 | ->has_self_closing_flag() |
isset($token_name) | 20–31 | ->get_namespace() |
isset($token_name) | 23–34 | ->get_namespace(), ->has_self_closing_flag() |
isset($token_name) | 23–34 | ->get_token_name(), ->has_self_closing_flag() |
isset($token_name) | 23–34 | ->get_token_name(), ->get_namespace() |
!$node && isset($token_name) && $token_name !== "html" && $token_namespace === "html" | 25–32 | ::is_void() |
$node && isset($token_name) | 26–37 | ->get_token_name(), ->get_namespace(), ->has_self_closing_flag() |
isset($token_name) && $token_name !== "html" && $token_namespace === "html" | 28–35 | ->has_self_closing_flag(), ::is_void() |
isset($token_name) && $token_name !== "html" && $token_namespace === "html" | 28–35 | ->get_namespace(), ::is_void() |
isset($token_name) && $token_name !== "html" && $token_namespace === "html" | 28–35 | ->get_token_name(), ::is_void() |
4 further outcomes, up to 41 instructions
isset($token_name) && $token_name !== "html" && $token_namespace === "html" | 31–38 | ->get_namespace(), ->has_self_closing_flag(), ::is_void() |
isset($token_name) && $token_name !== "html" && $token_namespace === "html" | 31–38 | ->get_token_name(), ->has_self_closing_flag(), ::is_void() |
isset($token_name) && $token_name !== "html" && $token_namespace === "html" | 31–38 | ->get_token_name(), ->get_namespace(), ::is_void() |
$node && isset($token_name) && $token_name !== "html" && $token_namespace === "html" | 34–41 | ->get_token_name(), ->get_namespace(), ->has_self_closing_flag(), ::is_void() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 39 | 7–38 | 11 | 3 fewer instructions than PHP 8.5 |
| 8.5 | 42 | 7–41 | 11 | |
| 8.4 | 42 | 7–41 | 11 | |
| 8.3 | 42 | 7–41 | 11 | |
| 8.2 | 42 | 7–41 | 11 | |
| 8.1 | 42 | 7–41 | 11 | |
| 7.4 | 42 | 7–41 | 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 · 4
- WP_HTML_Processor::get_token_name()Returns the node name represented by the token.
- WP_HTML_Processor::get_namespace()Indicates the namespace of the current token, or "html" if there is none.
- WP_HTML_Processor::has_self_closing_flag()Indicates if the currently matched tag contains the self-closing flag.
- WP_HTML_Processor::is_void()Returns whether a given element is an HTML Void Element
Used by · 2
- 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::step()Steps through the HTML document and stop at the next tag, if any.
Source code
public function expects_closer( ?WP_HTML_Token $node = null ): ?bool { $token_name = $node->node_name ?? $this->get_token_name(); if ( ! isset( $token_name ) ) { return null; } $token_namespace = $node->namespace ?? $this->get_namespace(); $token_has_self_closing = $node->has_self_closing_flag ?? $this->has_self_closing_flag(); return ! ( // Comments, text nodes, and other atomic tokens. '#' === $token_name[0] || // Doctype declarations. 'html' === $token_name || // Void elements. ( 'html' === $token_namespace && self::is_void( $token_name ) ) || // Special atomic elements. ( 'html' === $token_namespace && in_array( $token_name, array( 'IFRAME', 'NOEMBED', 'NOFRAMES', 'SCRIPT', 'STYLE', 'TEXTAREA', 'TITLE', 'XMP' ), true ) ) || // Self-closing elements in foreign content. ( 'html' !== $token_namespace && $token_has_self_closing ) ); }Changelog
Introduced in 6.6.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.