WP_Translation_File_MO::detect_endian_and_validate_file( string $header ): false|'V'|'N'

In this article

Detects endian and validates file.

Parameters

$headerstringrequired
File contents.

Return

false|'V'|'N' V for little endian, N for big endian, or false on failure.

Source

protected function detect_endian_and_validate_file( string $header ) {
	$big = unpack( 'N', $header );

	if ( false === $big ) {
		return false;
	}

	$big = reset( $big );

	if ( false === $big ) {
		return false;
	}

	$little = unpack( 'V', $header );

	if ( false === $little ) {
		return false;
	}

	$little = reset( $little );

	if ( false === $little ) {
		return false;
	}

	// Force cast to an integer as it can be a float on x86 systems. See https://core.trac.wordpress.org/ticket/60678.
	if ( (int) self::MAGIC_MARKER === $big ) {
		return 'N';
	}

	// Force cast to an integer as it can be a float on x86 systems. See https://core.trac.wordpress.org/ticket/60678.
	if ( (int) self::MAGIC_MARKER === $little ) {
		return 'V';
	}

	$this->error = 'Magic marker does not exist';
	return false;
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.