maxmind / GeoIP2-php

PHP API for GeoIP2 webservice client and database reader
https://maxmind.github.io/GeoIP2-php/
Apache License 2.0
2.33k stars 276 forks source link

PHP Fatal error: Cannot use string offset as an array #83

Closed xuanskyer closed 7 years ago

xuanskyer commented 7 years ago

PHP Fatal error: Cannot use string offset as an array in /vendor/geoip2/geoip2/src/Database/Reader.php on line 195

oschwald commented 7 years ago

How are you getting this? The MaxMind\Db\Reader returns an array or null. If we are getting something else back, it is a bug and should be a fatal error.

xuanskyer commented 7 years ago

I haven't reproduced the mistake yet. Only found this error in php_errors.log :(

oschwald commented 7 years ago

What version of this package and MaxMind\Db\Reader are you using? Are you using the C extension?

xuanskyer commented 7 years ago

@oschwald

geoip2 version 2.4.2 maxmind-db/reader version 1.1.1

using php package, not C extension.

oschwald commented 7 years ago

Have you been getting any InvalidDatabaseException exceptions? My first thought is that the database file is corrupt in some way. Generally, this would cause the above exception to be thrown, but it could occasionally result in an error like this.

Karagath commented 7 years ago

Error: Cannot use string offset as an array # 6: vendor/geoip2/geoip2/src/Database/Reader.php(195): modelFor with data $class = Country, $ipAddress = 4. ..., $type = Country # 5: vendor/geoip2/geoip2/src/Database/Reader.php(87): country with data $ipAddress = 4.15.238.175

Hope that helps the error hunting

Karagath commented 7 years ago

Upgrading the ip database removed this problem for me but I assume that should not be able to happen

oschwald commented 7 years ago

Besides this error, were you also getting exceptions from MaxMind\Db\Reader? The only way this could happen is on a corrupt database, which should be generating an exception on almost every call.

Karagath commented 7 years ago

You are probably correct, it appears the ip-range number above went back to triggering the same error, I suspect something in the release process causes the problem.

Oddly it only triggers on the very first ip-ranges, the majority of requests work fine but 1. 2. 4. & 5. ranges have all caused the error to happen. Possibly the corruption is limited there, for whatever reasons.

oschwald commented 7 years ago

Would it be possible for you to send me the corrupt database at goschwald@maxmind.com? Thanks!