wppaste
WordPress

getid3_mp3::MPEGaudioHeaderValid( array $rawarray, bool $echoerrors = false, bool $allowBitrate15 = false ): bool

Source
wp-includes/ID3/module.audio.mp3.php:1846

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

$rawarrayarray
$echoerrorsbooloptional
Default: false
$allowBitrate15booloptional
Default: false

Return value

bool

Performance profile

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

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
6–87

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
3

3 places 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_mp3::MPEGaudioHeaderValid() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always6–66none
isset($rawarray) && empty($MPEGaudioVersionLookup)46–87::MPEGaudioVersionArray(), ::MPEGaudioLayerArray(), ::MPEGaudioBitrateArray(), ::MPEGaudioFrequencyArray(), ::MPEGaudioChannelModeArray(), ::MPEGaudioModeExtensionArray(), ::MPEGaudioEmphasisArray()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1336–8719
8.51336–8719
8.41336–8719
8.31336–8719
8.21336–8719
8.11336–87197 fewer instructions than PHP 7.4
7.41406–8919

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

Used by · 3

Source code

	public static function MPEGaudioHeaderValid($rawarray, $echoerrors=false, $allowBitrate15=false) {		if (!isset($rawarray['synch']) || ($rawarray['synch'] & 0x0FFE) != 0x0FFE) {			return false;		} 		static $MPEGaudioVersionLookup;		static $MPEGaudioLayerLookup;		static $MPEGaudioBitrateLookup;		static $MPEGaudioFrequencyLookup;		static $MPEGaudioChannelModeLookup;		static $MPEGaudioModeExtensionLookup;		static $MPEGaudioEmphasisLookup;		if (empty($MPEGaudioVersionLookup)) {			$MPEGaudioVersionLookup       = self::MPEGaudioVersionArray();			$MPEGaudioLayerLookup         = self::MPEGaudioLayerArray();			$MPEGaudioBitrateLookup       = self::MPEGaudioBitrateArray();			$MPEGaudioFrequencyLookup     = self::MPEGaudioFrequencyArray();			$MPEGaudioChannelModeLookup   = self::MPEGaudioChannelModeArray();			$MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray();			$MPEGaudioEmphasisLookup      = self::MPEGaudioEmphasisArray();		} 		if (isset($MPEGaudioVersionLookup[$rawarray['version']])) {			$decodedVersion = $MPEGaudioVersionLookup[$rawarray['version']];		} else {			echo ($echoerrors ? "\n".'invalid Version ('.$rawarray['version'].')' : '');			return false;		}		if (isset($MPEGaudioLayerLookup[$rawarray['layer']])) {			$decodedLayer = $MPEGaudioLayerLookup[$rawarray['layer']];		} else {			echo ($echoerrors ? "\n".'invalid Layer ('.$rawarray['layer'].')' : '');			return false;		}		if (!isset($MPEGaudioBitrateLookup[$decodedVersion][$decodedLayer][$rawarray['bitrate']])) {			echo ($echoerrors ? "\n".'invalid Bitrate ('.$rawarray['bitrate'].')' : '');			if ($rawarray['bitrate'] == 15) {				// known issue in LAME 3.90 - 3.93.1 where free-format has bitrate ID of 15 instead of 0				// let it go through here otherwise file will not be identified				if (!$allowBitrate15) {					return false;				}			} else {				return false;			}		}		if (!isset($MPEGaudioFrequencyLookup[$decodedVersion][$rawarray['sample_rate']])) {			echo ($echoerrors ? "\n".'invalid Frequency ('.$rawarray['sample_rate'].')' : '');			return false;		}		if (!isset($MPEGaudioChannelModeLookup[$rawarray['channelmode']])) {			echo ($echoerrors ? "\n".'invalid ChannelMode ('.$rawarray['channelmode'].')' : '');			return false;		}		if (!isset($MPEGaudioModeExtensionLookup[$decodedLayer][$rawarray['modeextension']])) {			echo ($echoerrors ? "\n".'invalid Mode Extension ('.$rawarray['modeextension'].')' : '');			return false;		}		if (!isset($MPEGaudioEmphasisLookup[$rawarray['emphasis']])) {			echo ($echoerrors ? "\n".'invalid Emphasis ('.$rawarray['emphasis'].')' : '');			return false;		}		// These are just either set or not set, you can't mess that up :)		// $rawarray['protection'];		// $rawarray['padding'];		// $rawarray['private'];		// $rawarray['copyright'];		// $rawarray['original']; 		return true;	}

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.audio.mp3.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.