LaravelPostcodes
LaravelPostcodes copied to clipboard
Array to string conversion warning on getPoscodes method
Detailed description
When calling getPostcodes
without providing the second argument ($filter
), an "Array to string conversion" warning is raised.
<warning>PHP Warning: Array to string conversion in vendor/juststeveking/laravel-postcodes/src/Service/PostcodeService.php on line 97</warning>
Possible implementation
In the file https://github.com/JustSteveKing/LaravelPostcodes/blob/8ccc6d619aeaf13cc2eeff746f8e8ce390bde49e/src/Service/PostcodeService.php#L92-L94
Add the following:
} else {
$filter = '';
}
So that $filter can be used as a string in the call below https://github.com/JustSteveKing/LaravelPostcodes/blob/8ccc6d619aeaf13cc2eeff746f8e8ce390bde49e/src/Service/PostcodeService.php#L96-L99
Your environment
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
- Version used (e.g. PHP 5.6, HHVM 3): PHP 8.0
- Operating system and version (e.g. Ubuntu 16.04, Windows 7): macOS Monterey (12)
- Link to your project: N/A
php artisan tinker
>>> $postcode_service = resolve(JustSteveKing\LaravelPostcodes\Service\PostcodeService::class);
>>> $postcode_service->getPostcodes(['SW1A 2AA']);
<warning>PHP Warning: Array to string conversion in /Users/marcomarassi/Projects/car-parks-api-laravel/vendor/juststeveking/laravel-postcodes/src/Service/PostcodeService.php on line 97</warning>
...
Happy to open a PR with the change if it's easier :)
This is now fixed in PR#51
Thanks!