wppaste
WordPress

AtomParser::start_element( $parser, $name, $attrs )

Source
wp-includes/atomlib.php:198

Compatibility

WordPress
core
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

$parser
$name
$attrs

Performance profile

How much work a call to AtomParser::start_element() 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
48–145

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 244.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What one call costs · 11 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost AtomParser::start_element() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($value) && !$tag && $tag != "link" && $tag != "category"48–52explode(), array_pop(), ->_p(), array_unshift()
empty($value) && !$tag53–58explode(), array_pop(), ->_p(), array_unshift(), array_push()
empty($value) && $tag74–97explode(), array_pop(), ->_p(), array_unshift(), array_keys(), array_keys()
!empty($value) && ->is_declared_content_ns()97–104explode(), array_pop(), ->_p(), array_unshift(), array_keys(), array_values(), array_map(), join(), ->ns_to_prefix(), ->is_declared_content_ns()
!empty($value) && ->is_declared_content_ns()98–107explode(), array_pop(), ->_p(), array_unshift(), trigger_error(), array_keys(), array_values(), array_map(), join(), ->ns_to_prefix(), ->is_declared_content_ns()
!empty($value) && !->is_declared_content_ns()103–110explode(), array_pop(), ->_p(), array_unshift(), array_keys(), array_values(), array_map(), join(), ->ns_to_prefix(), ->is_declared_content_ns(), array_push()
!empty($value) && !->is_declared_content_ns()104–113explode(), array_pop(), ->_p(), array_unshift(), trigger_error(), array_keys(), array_values(), array_map(), join(), ->ns_to_prefix(), ->is_declared_content_ns(), array_push()
!empty($value) && ->is_declared_content_ns()127–136explode(), array_pop(), ->_p(), array_unshift(), array_keys(), array_values(), array_map(), join(), ->ns_to_prefix(), ->is_declared_content_ns(), array_unshift(), array_keys(), array_values(), array_map(), join()
!empty($value) && ->is_declared_content_ns()128–139explode(), array_pop(), ->_p(), array_unshift(), trigger_error(), array_keys(), array_values(), array_map(), join(), ->ns_to_prefix(), ->is_declared_content_ns(), array_unshift(), array_keys(), array_values(), array_map(), join()
!empty($value) && !->is_declared_content_ns()133–142explode(), array_pop(), ->_p(), array_unshift(), array_keys(), array_values(), array_map(), join(), ->ns_to_prefix(), ->is_declared_content_ns(), array_push(), array_unshift(), array_keys(), array_values(), array_map(), join()
!empty($value) && !->is_declared_content_ns()134–145explode(), array_pop(), ->_p(), array_unshift(), trigger_error(), array_keys(), array_values(), array_map(), join(), ->ns_to_prefix(), ->is_declared_content_ns(), array_push(), array_unshift(), array_keys(), array_values(), array_map(), join()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev24448–14521
8.524448–14521
8.424448–1452112 fewer instructions than PHP 8.3
8.325654–14521
8.225654–145211 more instruction than PHP 8.1
8.125554–145211 fewer instruction than PHP 7.4
7.425654–14521

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 · 5

Source code

    function start_element($parser, $name, $attrs) {         $name_parts = explode(":", $name);        $tag        = array_pop($name_parts);         switch($name) {            case $this->NS . ':feed':                $this->current = $this->feed;                break;            case $this->NS . ':entry':                $this->current = new AtomEntry();                break;        };         $this->_p("start_element('$name')");        #$this->_p(print_r($this->ns_contexts,true));        #$this->_p('current(' . $this->current . ')');         array_unshift($this->ns_contexts, $this->ns_decls);         $this->depth++;         if(!empty($this->in_content)) {             $this->content_ns_decls = array();             if($this->is_html || $this->is_text)                trigger_error("Invalid content in element found. Content must not be of type text or html if it contains markup.");             $attrs_prefix = array();             // resolve prefixes for attributes            foreach($attrs as $key => $value) {                $with_prefix = $this->ns_to_prefix($key, true);                $attrs_prefix[$with_prefix[1]] = $this->xml_escape($value);            }             $attrs_str = join(' ', array_map($this->map_attrs_func, array_keys($attrs_prefix), array_values($attrs_prefix)));            if(strlen($attrs_str) > 0) {                $attrs_str = " " . $attrs_str;            }             $with_prefix = $this->ns_to_prefix($name);             if(!$this->is_declared_content_ns($with_prefix[0])) {                array_push($this->content_ns_decls, $with_prefix[0]);            }             $xmlns_str = '';            if(count($this->content_ns_decls) > 0) {                array_unshift($this->content_ns_contexts, $this->content_ns_decls);                $xmlns_str .= join(' ', array_map($this->map_xmlns_func, array_keys($this->content_ns_contexts[0]), array_values($this->content_ns_contexts[0])));                if(strlen($xmlns_str) > 0) {                    $xmlns_str = " " . $xmlns_str;                }            }             array_push($this->in_content, array($tag, $this->depth, "<". $with_prefix[1] ."{$xmlns_str}{$attrs_str}" . ">"));         } else if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS) || in_array($tag, $this->ATOM_SIMPLE_ELEMENTS)) {            $this->in_content = array();            $this->is_xhtml = $attrs['type'] == 'xhtml';            $this->is_html = $attrs['type'] == 'html' || $attrs['type'] == 'text/html';            $this->is_text = !in_array('type',array_keys($attrs)) || $attrs['type'] == 'text';            $type = $this->is_xhtml ? 'XHTML' : ($this->is_html ? 'HTML' : ($this->is_text ? 'TEXT' : $attrs['type']));             if(in_array('src',array_keys($attrs))) {                $this->current->$tag = $attrs;            } else {                array_push($this->in_content, array($tag,$this->depth, $type));            }        } else if($tag == 'link') {            array_push($this->current->links, $attrs);        } else if($tag == 'category') {            array_push($this->current->categories, $attrs);        }         $this->ns_decls = array();    }

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/atomlib.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.