: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace Wordfence\MmdbReader;
use Wordfence\MmdbReader\Exception\FormatException;
const MAX_LENGTH = 131072; //128 * 1024;
const FIELD_MAJOR_VERSION = 'binary_format_major_version';
const FIELD_NODE_COUNT = 'node_count';
const FIELD_RECORD_SIZE = 'record_size';
const FIELD_IP_VERSION = 'ip_version';
const FIELD_BUILD_EPOCH = 'build_epoch';
public function __construct($data) {
private function getField($key, $default = null, &$exists = null) {
if (!array_key_exists($key, $this->data)) {
return $this->data[$key];
private function requireField($key) {
$value = $this->getField($key, null, $exists);
throw new FormatException("Metadata field {$key} is missing");
public function requireInteger($key) {
$value = $this->requireField($key);
throw new FormatException("Field {$key} should be an integer, received: " . print_r($value, true));
public function getMajorVersion() {
return $this->requireInteger(self::FIELD_MAJOR_VERSION);
public function getNodeCount() {
return $this->requireInteger(self::FIELD_NODE_COUNT);
public function getRecordSize() {
return $this->requireInteger(self::FIELD_RECORD_SIZE);
public function getIpVersion() {
return $this->requireInteger(self::FIELD_IP_VERSION);
public function getBuildEpoch() {
return $this->requireInteger(self::FIELD_BUILD_EPOCH);
public static function parse($handle) {
$offset = $handle->getPosition();
$parser = new DataFieldParser($handle, $offset);
$value = $parser->parseField();
throw new FormatException('Unexpected field type found when metadata map was expected: ' . print_r($value, true));