Skip to content

ext/json: Stop encoding after a key fails to encode - #24123

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/aph-json-encoder-key-escape-success-ba2c-84-work
Open

iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/aph-json-encoder-key-escape-success-ba2c-84-work

Conversation

@iliaal

@iliaal iliaal commented Oct 4, 2026

Copy link
Copy Markdown
Member

When an array or object key failed to encode, json_encode() carried on with the remaining values unless JSON_PARTIAL_OUTPUT_ON_ERROR was set, so jsonSerialize() still ran on later values and a later error could replace the one that caused the failure. Both key sites now bail out the same way a failed value already does; partial output is unchanged.

A failure to escape an array or object key was ignored unless
JSON_PARTIAL_OUTPUT_ON_ERROR was set, so encoding went on: later values
still ran user code such as jsonSerialize(), and a later error replaced
the one that was reported, e.g. a NAN value after an invalid UTF-8 key
reported "Inf and NaN cannot be JSON encoded". Both key sites, the
declared-property loop and the property table loop, now return FAILURE
the same way a failed value does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant