PO::read_entry( resource $f, int $lineno = 0 ): null|false|array
- Source
wp-includes/pomo/po.php:338
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
$fresource$linenointoptional- Default:
0
Return value
null|false|array
Performance profile
How much work a call to PO::read_entry() 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
- 18–71
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 230.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost PO::read_entry() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!feof() | 18 | ::PO(), feof() |
feof() | 23–37 | ::PO(), feof(), ::is_final() |
$line !== "\n" && preg_match() && !::is_final() && $context !== "comment" | 31 | ::PO(), preg_match(), ::is_final() |
$line !== "\n" && !::is_final() && $context !== "comment" | 37 | ::PO(), preg_match(), preg_match(), ::is_final() |
$line !== "\n" && preg_match() && ::is_final() | 42–49 | ::PO(), preg_match(), ::is_final(), ::PO() |
$line !== "\n" && $context !== "msgid" | 44 | ::PO(), preg_match(), preg_match(), preg_match(), preg_match() |
$line !== "\n" && !::is_final() && $context !== "msgctxt" && $context !== "comment" | 45 | ::PO(), preg_match(), preg_match(), preg_match(), ::is_final() |
$line !== "\n" && ::is_final() | 48–55 | ::PO(), preg_match(), preg_match(), ::is_final(), ::PO() |
$line !== "\n" && $context !== "msgid" | 50 | ::PO(), preg_match(), preg_match(), preg_match(), preg_match(), preg_match() |
$line !== "\n" && ::is_final() | 54–61 | ::PO(), preg_match(), preg_match(), preg_match(), ::is_final(), ::PO() |
$line !== "\n" && !preg_match() | 56–58 | ::PO(), preg_match(), preg_match(), preg_match(), preg_match(), preg_match(), preg_match() |
$line !== "\n" && !preg_match() && $line | 61–71 | ::PO(), preg_match(), preg_match(), preg_match(), preg_match(), preg_match(), preg_match(), ::PO() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 230 | 18–71 | 37 | |
| 8.5 | 230 | 18–71 | 37 | |
| 8.4 | 230 | 18–71 | 37 | 5 fewer instructions than PHP 8.3 |
| 8.3 | 235 | 18–76 | 37 | |
| 8.2 | 235 | 18–76 | 37 | |
| 8.1 | 235 | 18–76 | 37 | 1 more instruction than PHP 7.4 |
| 7.4 | 234 | 18–76 | 37 |
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
- Translation_Entry::__construct()
- PO::read_line()
- PO::is_final()Helper function for read_entry
- PO::add_comment_to_entry()
- PO::unpoify()Gives back the original string from a PO-formatted string
Used by · 1
Source code
public function read_entry( $f, $lineno = 0 ) { $entry = new Translation_Entry(); // Where were we in the last step. // Can be: comment, msgctxt, msgid, msgid_plural, msgstr, msgstr_plural. $context = ''; $msgstr_index = 0; while ( true ) { ++$lineno; $line = PO::read_line( $f ); if ( ! $line ) { if ( feof( $f ) ) { if ( self::is_final( $context ) ) { break; } elseif ( ! $context ) { // We haven't read a line and EOF came. return null; } else { return false; } } else { return false; } } if ( "\n" === $line ) { continue; } $line = trim( $line ); if ( preg_match( '/^#/', $line, $m ) ) { // The comment is the start of a new entry. if ( self::is_final( $context ) ) { PO::read_line( $f, 'put-back' ); --$lineno; break; } // Comments have to be at the beginning. if ( $context && 'comment' !== $context ) { return false; } // Add comment. $this->add_comment_to_entry( $entry, $line ); } elseif ( preg_match( '/^msgctxt\s+(".*")/', $line, $m ) ) { if ( self::is_final( $context ) ) { PO::read_line( $f, 'put-back' ); --$lineno; break; } if ( $context && 'comment' !== $context ) { return false; } $context = 'msgctxt'; $entry->context .= PO::unpoify( $m[1] ); } elseif ( preg_match( '/^msgid\s+(".*")/', $line, $m ) ) { if ( self::is_final( $context ) ) { PO::read_line( $f, 'put-back' ); --$lineno; break; } if ( $context && 'msgctxt' !== $context && 'comment' !== $context ) { return false; } $context = 'msgid'; $entry->singular .= PO::unpoify( $m[1] ); } elseif ( preg_match( '/^msgid_plural\s+(".*")/', $line, $m ) ) { if ( 'msgid' !== $context ) { return false; } $context = 'msgid_plural'; $entry->is_plural = true; $entry->plural .= PO::unpoify( $m[1] ); } elseif ( preg_match( '/^msgstr\s+(".*")/', $line, $m ) ) { if ( 'msgid' !== $context ) { return false; } $context = 'msgstr'; $entry->translations = array( PO::unpoify( $m[1] ) ); } elseif ( preg_match( '/^msgstr\[(\d+)\]\s+(".*")/', $line, $m ) ) { if ( 'msgid_plural' !== $context && 'msgstr_plural' !== $context ) { return false; } $context = 'msgstr_plural'; $msgstr_index = $m[1];Changelog
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 6.8.8 tag, from
src/wp-includes/pomo/po.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.