fix(streaming): initialize tool_use input as string to prevent array-to-string warning#1
Open
sideshot wants to merge 2 commits intoclaude-php:mainfrom
Open
fix(streaming): initialize tool_use input as string to prevent array-to-string warning#1sideshot wants to merge 2 commits intoclaude-php:mainfrom
sideshot wants to merge 2 commits intoclaude-php:mainfrom
Conversation
…to-string warning
Claude API sends `"input": {}` in content_block_start for tool_use blocks,
which PHP json_decode converts to an empty array []. When input_json_delta
events arrive, the null coalescing `$block['input'] ?? ''` returns [] (not
null), causing "Array to string conversion" warning on concatenation.
The fix initializes `input` to empty string for tool_use blocks in
handleContentBlockStart, matching the existing pattern for text blocks.
Root cause verified with runtime instrumentation showing:
- content_block_start: input_type="array", input_value=[]
- First concat: [] . partial_json → warning + "Array{\"query..."
- After fix: input_type="string", input_value="" → correct concat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fix(streaming): initialize tool_use input as string to prevent array-to-string warning
Claude API sends
"input": {}in content_block_start for tool_use blocks,which PHP json_decode converts to an empty array []. When input_json_delta
events arrive, the null coalescing
$block['input'] ?? ''returns [] (notnull), causing "Array to string conversion" warning on concatenation.
The fix initializes
inputto empty string for tool_use blocks inhandleContentBlockStart, matching the existing pattern for text blocks.
Root cause verified with runtime instrumentation showing: