LaravelPostcodes icon indicating copy to clipboard operation
LaravelPostcodes copied to clipboard

Array to string conversion warning on getPoscodes method

Open thtg88 opened this issue 3 years ago • 1 comments

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>
...

thtg88 avatar Nov 10 '21 11:11 thtg88

Happy to open a PR with the change if it's easier :)

thtg88 avatar Nov 10 '21 11:11 thtg88

This is now fixed in PR#51

nathandaly avatar Oct 05 '23 14:10 nathandaly

Thanks!

thtg88 avatar Oct 07 '23 12:10 thtg88