Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getid3_lib::array_min finds max instead of min #247

Closed
quasilyte opened this issue May 20, 2020 · 1 comment
Closed

getid3_lib::array_min finds max instead of min #247

quasilyte opened this issue May 20, 2020 · 1 comment

Comments

@quasilyte
Copy link

quasilyte commented May 20, 2020

https://github.com/JamesHeinrich/getID3/blob/master/getid3/getid3.lib.php#L707

Both getid3_lib::array_min and getid3_lib::array_max seem to find array max.

This might be a copy/paste mistake. I assume array_max was copied, variables were renamed, but the condition was not changed.

	/**
	 * @param array $arraydata
	 * @param bool  $returnkey
	 *
	 * @return int|false
	 */
	public static function array_max($arraydata, $returnkey=false) {
		$maxvalue = false;
		$maxkey = false;
		foreach ($arraydata as $key => $value) {
			if (!is_array($value)) {
				if ($value > $maxvalue) {
					$maxvalue = $value;
					$maxkey = $key;
				}
			}
		}
		return ($returnkey ? $maxkey : $maxvalue);
	}

	/**
	 * @param array $arraydata
	 * @param bool  $returnkey
	 *
	 * @return int|false
	 */
	public static function array_min($arraydata, $returnkey=false) {
		$minvalue = false;
		$minkey = false;
		foreach ($arraydata as $key => $value) {
			if (!is_array($value)) {
				if ($value > $minvalue) {
					$minvalue = $value;
					$minkey = $key;
				}
			}
		}
		return ($returnkey ? $minkey : $minvalue);
}

Note that it's not enough to change > to <. The initial value of minvalue needs to be changed too, otherwise array_min could return false.

@JamesHeinrich
Copy link
Owner

Thanks, fixed in 13dc22a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants