saintsystems / odata-client-php

OData Client Library for PHP
MIT License
141 stars 103 forks source link

PHP Deprecation Warnings #132

Closed ZacharyDuBois closed 1 year ago

ZacharyDuBois commented 1 year ago

When the OData service returns an empty (null) response, that null value is passed into json_decode within ODataResponse.php:93. This also results in an undefined array key access as well.

Warning: Undefined array key 0 in./vendor/saintsystems/odata-client/src/ODataResponse.php on line 93
Deprecated: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in ./vendor/saintsystems/odata-client/src/ODataResponse.php on line 93

Honestly, removing lines 90-98 would be desirable. If a garbage response is returned from the server, the client should error out instead of attempting to figure it out.

Additionally, validate the JSON by checking json_last_error() === JSON_ERROR_NONE or pass json_decode(json: $body, associative: true, flags: JSON_THROW_ON_ERROR) to have it throw an exception.

This library is already proving super useful! Would love to see more work on it. I will PR these changes if I have some time later on.

anderly commented 1 year ago

Deprecation warning should be fixed by #140.