wppaste
WordPress

getid3_id3v1::Analyze(): bool

Source
wp-includes/ID3/module.tag.id3v1.php:26

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.

Return value

bool

Performance profile

How much work a call to getid3_id3v1::Analyze() 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 how much data it finds.

Instructions
36–237

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

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 · 38 distinct outcomes

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

WhenInstructionsCalls it makes
::getid3_lib()36–44::getid3_lib(), ->fseek(), ->fread(), ->fread()
::getid3_lib()49::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->warning()
::getid3_lib() && !isset($ParsedID3v1) && $id3v1tag === false151–172::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ->GenerateID3v1Tag()
::getid3_lib() && !isset($ParsedID3v1)156–177::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && isset($ParsedID3v1) && $id3v1tag === false157–178::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ->LookupGenreID(), ->GenerateID3v1Tag()
::getid3_lib() && isset($ParsedID3v1)162–183::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !isset($ParsedID3v1) && $id3v1tag === false167–180::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ->GenerateID3v1Tag()
::getid3_lib() && !isset($ParsedID3v1) && $id3v1tag !== false169–182::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !isset($ParsedID3v1)172–185::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && isset($ParsedID3v1) && $id3v1tag === false173–186::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ->LookupGenreID(), ->GenerateID3v1Tag()
::getid3_lib() && isset($ParsedID3v1) && $id3v1tag !== false175–188::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && isset($ParsedID3v1)178–191::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning()
26 further outcomes, up to 237 instructions
::getid3_lib() && empty($ParsedID3v1) && !isset($ParsedID3v1) && $id3v1tag !== false185–190::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && !isset($ParsedID3v1) && $id3v1tag === false187–204::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->GenerateID3v1Tag()
::getid3_lib() && empty($ParsedID3v1) && isset($ParsedID3v1) && $id3v1tag !== false191–196::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && !isset($ParsedID3v1)192–209::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && isset($ParsedID3v1) && $id3v1tag === false193–210::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && !isset($ParsedID3v1) && $id3v1tag === false196–213::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->GenerateID3v1Tag()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && isset($ParsedID3v1)198–215::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && !isset($ParsedID3v1)201–218::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && isset($ParsedID3v1) && $id3v1tag === false202–219::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && !isset($ParsedID3v1) && $id3v1tag === false203–212::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->GenerateID3v1Tag()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && !isset($ParsedID3v1) && $id3v1tag !== false205–214::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && isset($ParsedID3v1)207–224::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && !isset($ParsedID3v1)208–217::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && isset($ParsedID3v1) && $id3v1tag === false209–218::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && isset($ParsedID3v1) && $id3v1tag !== false211–220::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && !isset($ParsedID3v1) && $id3v1tag === false212–221::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->GenerateID3v1Tag()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && !isset($ParsedID3v1) && $id3v1tag !== false214–223::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && isset($ParsedID3v1)214–223::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && !isset($ParsedID3v1)217–226::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && isset($ParsedID3v1) && $id3v1tag === false218–227::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag()
::getid3_lib() && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && isset($ParsedID3v1) && $id3v1tag !== false220–229::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && !isset($ParsedID3v1) && $id3v1tag !== false221–222::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && isset($ParsedID3v1)223–232::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && $value === false && isset($ParsedID3v1) && $id3v1tag !== false227::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && !isset($ParsedID3v1) && $id3v1tag !== false230–231::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->GenerateID3v1Tag(), ->warning(), ->warning()
::getid3_lib() && empty($ParsedID3v1) && !$ParsedID3v1 && !$valuearray && $value && !ctype_digit() && isset($ParsedID3v1) && $id3v1tag !== false236–237::getid3_lib(), ->fseek(), ->fread(), ->fread(), ->cutfield(), ->cutfield(), ->cutfield(), ->cutfield(), ord(), ord(), ->cutfield(), ->LookupGenreName(), ctype_digit(), mb_convert_encoding(), iconv(), ->warning(), ->LookupGenreID(), ->GenerateID3v1Tag(), ->warning(), ->warning()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev28736–231293 more instructions than PHP 8.5
8.528436–23728
8.428436–2372839 fewer instructions than PHP 8.3
8.332342–276285 fewer instructions than PHP 8.2
8.232842–27628
8.132842–276281 more instruction than PHP 7.4
7.432742–27728

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

Source code

	public function Analyze() {		$info = &$this->getid3->info; 		if (!getid3_lib::intValueSupported($info['filesize'])) {			$this->warning('Unable to check for ID3v1 because file is larger than '.round(PHP_INT_MAX / 1073741824).'GB');			return false;		} elseif ($info['filesize'] < 128) {			$this->warning('Unable to check for ID3v1 because file is too small');			return false;		} 		if($info['filesize'] < 256) {			$this->fseek(-128, SEEK_END);			$preid3v1 = '';			$id3v1tag = $this->fread(128);		} else {			$this->fseek(-256, SEEK_END);			$preid3v1 = $this->fread(128);			$id3v1tag = $this->fread(128);		}  		if (substr($id3v1tag, 0, 3) == 'TAG') { 			$info['avdataend'] = $info['filesize'] - 128; 			$ParsedID3v1            = array();			$ParsedID3v1['title']   = $this->cutfield(substr($id3v1tag,   3, 30));			$ParsedID3v1['artist']  = $this->cutfield(substr($id3v1tag,  33, 30));			$ParsedID3v1['album']   = $this->cutfield(substr($id3v1tag,  63, 30));			$ParsedID3v1['year']    = $this->cutfield(substr($id3v1tag,  93,  4));			$ParsedID3v1['comment'] =                 substr($id3v1tag,  97, 30);  // can't remove nulls yet, track detection depends on them			$ParsedID3v1['genreid'] =             ord(substr($id3v1tag, 127,  1)); 			// If second-last byte of comment field is null and last byte of comment field is non-null			// then this is ID3v1.1 and the comment field is 28 bytes long and the 30th byte is the track number			if (($id3v1tag[125] === "\x00") && ($id3v1tag[126] !== "\x00")) {				$ParsedID3v1['track_number'] = ord(substr($ParsedID3v1['comment'], 29,  1));				$ParsedID3v1['comment']      =     substr($ParsedID3v1['comment'],  0, 28);			}			$ParsedID3v1['comment'] = $this->cutfield($ParsedID3v1['comment']); 			$ParsedID3v1['genre'] = $this->LookupGenreName($ParsedID3v1['genreid']);			if (!empty($ParsedID3v1['genre'])) {				unset($ParsedID3v1['genreid']);			}			if (empty($ParsedID3v1['genre']) || ($ParsedID3v1['genre'] == 'Unknown')) {				unset($ParsedID3v1['genre']);			} 			foreach ($ParsedID3v1 as $key => $value) {				$ParsedID3v1['comments'][$key][0] = $value;			}			$ID3v1encoding = $this->getid3->encoding_id3v1;			if ($this->getid3->encoding_id3v1_autodetect) {				// ID3v1 encoding detection hack START				// ID3v1 is defined as always using ISO-8859-1 encoding, but it is not uncommon to find files tagged with ID3v1 using Windows-1251 or other character sets				// Since ID3v1 has no concept of character sets there is no certain way to know we have the correct non-ISO-8859-1 character set, but we can guess				foreach ($ParsedID3v1['comments'] as $tag_key => $valuearray) {					foreach ($valuearray as $key => $value) {						if (preg_match('#^[\\x00-\\x40\\x80-\\xFF]+$#', $value) && !ctype_digit((string) $value)) { // check for strings with only characters above chr(128) and punctuation/numbers, but not just numeric strings (e.g. track numbers or years)							foreach (array('Windows-1251', 'KOI8-R') as $id3v1_bad_encoding) {								if (function_exists('mb_convert_encoding') && @mb_convert_encoding($value, $id3v1_bad_encoding, $id3v1_bad_encoding) === $value) {									$ID3v1encoding = $id3v1_bad_encoding;									$this->warning('ID3v1 detected as '.$id3v1_bad_encoding.' text encoding in '.$tag_key);									break 3;								} elseif (function_exists('iconv') && @iconv($id3v1_bad_encoding, $id3v1_bad_encoding, $value) === $value) {									$ID3v1encoding = $id3v1_bad_encoding;									$this->warning('ID3v1 detected as '.$id3v1_bad_encoding.' text encoding in '.$tag_key);									break 3;								}							}						}					}				}				// ID3v1 encoding detection hack END			} 			// ID3v1 data is supposed to be padded with NULL characters, but some taggers pad with spaces			$GoodFormatID3v1tag = $this->GenerateID3v1Tag(

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 7.1.0 tag, from src/wp-includes/ID3/module.tag.id3v1.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.