wppaste
WordPress

getid3_lib::CopyTagsToComments( array $ThisFileInfo, bool $option_tags_html = true ): bool

Source
wp-includes/ID3/getid3.lib.php:1570

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

$ThisFileInfoarray
$option_tags_htmlbooloptional
default true (just as in the main getID3 class)Default: true

Return value

bool

Performance profile

How much work a call to getid3_lib::CopyTagsToComments() 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
5–24

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

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

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

WhenInstructionsCalls it makes
always5–24none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev2325–24478 more instructions than PHP 8.5
8.52245–2446
8.42245–244644 fewer instructions than PHP 8.3
8.32685–2446
8.22685–2446
8.12685–2446
7.42685–2446

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

Used by · 1

Source code

	public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true) {		// Copy all entries from ['tags'] into common ['comments']		if (!empty($ThisFileInfo['tags'])) { 			// Some tag types can only support limited character sets and may contain data in non-standard encoding (usually ID3v1)			// and/or poorly-transliterated tag values that are also in tag formats that do support full-range character sets			// To make the output more user-friendly, process the potentially-problematic tag formats last to enhance the chance that			// the first entries in [comments] are the most correct and the "bad" ones (if any) come later.			// https://github.com/JamesHeinrich/getID3/issues/338			$processLastTagTypes = array('id3v1','riff');			foreach ($processLastTagTypes as $processLastTagType) {				if (isset($ThisFileInfo['tags'][$processLastTagType])) {					// bubble ID3v1 to the end, if present to aid in detecting bad ID3v1 encodings					$temp = $ThisFileInfo['tags'][$processLastTagType];					unset($ThisFileInfo['tags'][$processLastTagType]);					$ThisFileInfo['tags'][$processLastTagType] = $temp;					unset($temp);				}			}			foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) {				foreach ($tagarray as $tagname => $tagdata) {					foreach ($tagdata as $key => $value) {						if (!empty($value)) {							if (empty($ThisFileInfo['comments'][$tagname])) { 								// fall through and append value 							} elseif ($tagtype == 'id3v1') { 								$newvaluelength = strlen(trim($value));								foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {									$oldvaluelength = strlen(trim($existingvalue));									if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {										// new value is identical but shorter-than (or equal-length to) one already in comments - skip										break 2;									} 									if (function_exists('mb_convert_encoding')) {										if (trim($value) == trim(substr(mb_convert_encoding($existingvalue, $ThisFileInfo['id3v1']['encoding'], $ThisFileInfo['encoding']), 0, 30))) {											// value stored in ID3v1 appears to be probably the multibyte value transliterated (badly) into ISO-8859-1 in ID3v1.											// As an example, Foobar2000 will do this if you tag a file with Chinese or Arabic or Cyrillic or something that doesn't fit into ISO-8859-1 the ID3v1 will consist of mostly "?" characters, one per multibyte unrepresentable character											break 2;										}									}								} 							} elseif (!is_array($value)) { 								$newvaluelength   =    strlen(trim($value));								$newvaluelengthMB = mb_strlen(trim($value));								foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {									$oldvaluelength   =    strlen(trim($existingvalue));									$oldvaluelengthMB = mb_strlen(trim($existingvalue));									if (($newvaluelengthMB == $oldvaluelengthMB) && ($existingvalue == getid3_lib::iconv_fallback('UTF-8', 'ASCII', $value))) {										// https://github.com/JamesHeinrich/getID3/issues/338										// check for tags containing extended characters that may have been forced into limited-character storage (e.g. UTF8 values into ASCII)										// which will usually display unrepresentable characters as "?"										$ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);										break;									}									if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {										$ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);										break;									}								} 							}							if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {								$value = (is_string($value) ? trim($value) : $value);								if (!is_int($key) && !ctype_digit($key)) {									$ThisFileInfo['comments'][$tagname][$key] = $value;								} else {									if (!isset($ThisFileInfo['comments'][$tagname])) {										$ThisFileInfo['comments'][$tagname] = array($value);									} else {										$ThisFileInfo['comments'][$tagname][] = $value;									}								}							}						}

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.lib.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.