Ecomailcz / ecomail-php

PHP wrapper pro práci s Ecomail.cz API
12 stars 19 forks source link

Fix Bad condition on response format issue (#7) #18

Closed jakubboucek closed 4 years ago

jakubboucek commented 4 years ago

Fixes Bad condition on response format issue (#7)

@Degee was right, when response item was wrapped inside [], condition missed, because json_decode return content wrapped into array instead of object type.

var_dump(json_decode('[{"a":"b"},{"c":"d"}]'));
array(2) {
  [0] =>
  class stdClass#1 (1) {
    public $a =>
    string(1) "b"
  }
  [1] =>
  class stdClass#2 (1) {
    public $c =>
    string(1) "d"
  }
}

This PR is switch condition to array-based which matches both of response types.

IMPORTANT: I don't know reasons why this lib allows return responses as stdClass and I don't know all consequences about stdClass. Please test this PR well before merge it!

Resolves #7