Skip to content

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
sideshot:main
Open

fix(streaming): initialize tool_use input as string to prevent array-to-string warning#1
sideshot wants to merge 2 commits intoclaude-php:mainfrom
sideshot:main

Conversation

@sideshot
Copy link
Copy Markdown

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 [] (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

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant