wppaste
WordPress

getID3::GetFileFormat( string $filedata, string $filename = '' ): mixed|false

Source
wp-includes/ID3/getid3.php:1552

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

$filedatastring
$filenamestringoptional
Default: ''

Return value

mixed|false

Performance profile

How much work a call to getID3::GetFileFormat() 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
13–31

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What one call costs · 2 distinct outcomes

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

WhenInstructionsCalls it makes
always13–24->GetFileFormatArray()
$filename22–31->GetFileFormatArray(), ->GetFileFormatArray()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7813–319
8.57813–319
8.47813–31918 fewer instructions than PHP 8.3
8.39622–469
8.29622–469
8.19622–469
7.49622–469

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

Used by · 1

Source code

	public function GetFileFormat(&$filedata, $filename='') {		// this function will determine the format of a file based on usually		// the first 2-4 bytes of the file (8 bytes for PNG, 16 bytes for JPG,		// and in the case of ISO CD image, 6 bytes offset 32kb from the start		// of the file). 		// Identify file format - loop through $format_info and detect with reg expr		foreach ($this->GetFileFormatArray() as $format_name => $info) {			// The /s switch on preg_match() forces preg_match() NOT to treat			// newline (0x0A) characters as special chars but do a binary match			if (!empty($info['pattern']) && preg_match('#'.$info['pattern'].'#s', $filedata)) {				$info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';				return $info;			}		}  		if (preg_match('#\\.mp[123a]$#i', $filename)) {			// Too many mp3 encoders on the market put garbage in front of mpeg files			// use assume format on these if format detection failed			$GetFileFormatArray = $this->GetFileFormatArray();			$info = $GetFileFormatArray['mp3'];			$info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';			return $info;		} elseif (preg_match('#\\.mp[cp\\+]$#i', $filename) && preg_match('#[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0]#s', $filedata)) {			// old-format (SV4-SV6) Musepack header that has a very loose pattern match and could falsely match other data (e.g. corrupt mp3)			// only enable this pattern check if the filename ends in .mpc/mpp/mp+			$GetFileFormatArray = $this->GetFileFormatArray();			$info = $GetFileFormatArray['mpc'];			$info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';			return $info;		} elseif (preg_match('#\\.cue$#i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) {			// there's not really a useful consistent "magic" at the beginning of .cue files to identify them			// so until I think of something better, just go by filename if all other format checks fail			// and verify there's at least one instance of "TRACK xx AUDIO" in the file			$GetFileFormatArray = $this->GetFileFormatArray();			$info = $GetFileFormatArray['cue'];			$info['include']   = 'module.'.$info['group'].'.'.$info['module'].'.php';			return $info;		} 		return false;	}

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/getid3.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.