Good news for PHP developers using our geocoding API - version 4.0.0 of opencage/geocode has been released.
The new version of the SDK brings with it some meaningful changes, hence why we bumped to v4.0.0.
Specifically
-
Minimum PHP is now 8.2 (was 8.0).
-
Guzzle replaces the internal cURL/
fopenlogic. The SDK now depends onguzzlehttp/guzzle ^7.0, which Composer installs automatically. There is no longer a cURL/fopenfallback and no need to fiddle withallow_url_fopen. -
Dedicated reverse geocoding: new
geocodeReverse($latitude, $longitude)method — you no longer have to build a"lat,lng"string yourself. -
Asynchronous requests: new
geocodeAsync()andgeocodeReverseAsync()methods return a GuzzlePromiseInterface, allowing concurrent geocoding. -
Type declarations everywhere. All method parameters and return values are now typed. In particular
geocode()always returns anarrayor throws an\Exception— it no longer returnsnull/false(see Handling the Response below). -
Network failures are reported with a synthetic
status.codeof498instead of failing silently; the API key is redacted from the message.
Further Reading
Final Points
As with all of the 40+ SDKs for our geocoding API we welcome your ideas for improvement. We are continually rolling out various fixes and improvements in the future, but code contributions are of course also gladly received.
Our geocoding Agent Skill, which includes a reference file for working with PHP, has been adjusted accordingly.
Happy geocoding (whether in PHP or other languages),