sveawebpay / php-integration

SDK for Sveas payment methods (standalone and Svea Checkout)
Other
15 stars 19 forks source link

- Remove overcomplicated reinvented array builder #101

Closed timint closed 3 years ago

timint commented 3 years ago

No need to reinvent the wheel ;b

alexanderwiden95 commented 3 years ago

Setting the data type via (array) will only affect the first element. SveaSoapArrayBuilder->object_to_array() is recursive, making child objects into arrays as well.

timint commented 3 years ago

Oh, in that case here is a one liner for you:

$params = json_decode(json_encode($order), true);

<?php

$obj = new StdClass();
$obj->foo = 'bar';
$obj->obj = new StdClass();
$obj->obj->foo = 'bar';

var_dump(json_decode(json_encode($obj), true));

Outputs:

array(2) {
  ["foo"]=>
  string(3) "bar"
  ["obj"]=>
  array(1) {
    ["foo"]=>
    string(3) "bar"
  }
}