Fix crashes when "id" is not a string. #1602
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes
no longer crash. Sometimes "id" doesn't mean "identifier", sometimes it means "indonesia".
Detail
Right now,
StripeObject::__construct
is called from two important paths.StripeObject::constructFrom
, like this:ApiOperations::Retrieve::retrieve
, like this:This is troublesome, because in the first case,
$id
is "value of an id property that we are deserializing, e.g. it came back on a response", but in the second case,$id
means "stuff that the user passed intoretrieve
."In both cases,
$id
can be an array. InconstructFrom
it can be an array if "id" means "indonesia" and isn't an identifier. Viaretrieve
it can be an array if the user wanted to send some extra query parameters along with their call toretrieve
.Right now
$obj = StripeObject::constructFrom(['inner' => ['id' => ['foo' => 'bar']]]);
is crashing because we are always assuming the second case, i.e. the library sees['foo' => 'bar']
and crashes: "hey wait a minute! You're telling me to send ?foo=bar on a retrieve, but['foo' => 'bar']
doesn't have anid
field and I need to know id to do a retrieve!"The more disciplined change would be to take this logic completely out of the
StripeObject
constructor. It should not be shared. That needs to happen in a major, though.This less disciplined change is just to allow this code path to proceed without
id
being present. It's safe. This code path just would have crashed before.