Skip to content

Commit

Permalink
Convert keys to string in StripeObject::toArray() (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe authored Mar 18, 2020
1 parent e3f3789 commit d03bf95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/StripeObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public function toArray()
};

return \array_reduce(\array_keys($this->_values), function ($acc, $k) use ($maybeToArray) {
if ('_' === $k[0]) {
if ('_' === \substr((string) $k, 0, 1)) {
return $acc;
}
$v = $this->_values[$k];
Expand Down
8 changes: 6 additions & 2 deletions tests/Stripe/StripeObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function testToArray()
'foo' => 'a',
'list' => [1, 2, 3],
'null' => null,
'metadata' => [
'key' => 'value',
1 => 'one',
],
];
$s = StripeObject::constructFrom($array);

Expand All @@ -118,13 +122,13 @@ public function testToArrayRecursive()
'id' => 1,
// simple associative array that contains a StripeObject to help us
// test deep recursion
'nested' => ['object' => 'list', 'data' => $nested],
'nested' => ['object' => 'list', 'data' => [$nested]],
'list' => [$nested],
]);

$expected = [
'id' => 1,
'nested' => ['object' => 'list', 'data' => $nestedArray],
'nested' => ['object' => 'list', 'data' => [$nestedArray]],
'list' => [$nestedArray],
];

Expand Down

0 comments on commit d03bf95

Please sign in to comment.