Fixed #648 TelemetryEvent cannot handle nested array as $body argument. #649
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.
Description of the change
This resolves an issue with the current creation of a
TelemetryBody
instance inTelemetryEvent
. The core of the issue surrounds how the PHP spread operator (...
) works when it is uesd to expand an array into a function's named arguments.If an array has both string and numeric keys it can cause issues. The numeric keys are passed the the function as positional arguments. While the string keys are passed to the function as named arguments. If both a numeric key and a string key refer to the same argument PHP will throw and exception.
Consider the following example...
In this example both the
0
and'message'
keys resolve to the first argument, which causes PHP to throw an exception.Because we have been using the spread operator when the body of
TelemetryEvent
is an array we are experiancing the same issue. I am fixing this issue in this PR by adding a newfromArray()
method onTelemetryBody
. The new method is then used instead of the constructor for array bodys.Type of change
Related issues
Checklists
Development
Code review