phpstorm.dev

PHP ecosystem insights

PHP knowledge

Versioned PHP knowledge with primary sources and explicit verification dates.

Source checks through 2026-10-14 · 56 sources

Verified 2026-10-13 discussion Permanent entry

Opt-in JSON comments and trailing commas

Under discussion; not accepted. The RFC page (version 1.0, dated 2026-10-13, status Under Discussion) and the official RFC index both list it as under discussion. The proposed version is PHP 8.7. The page was created on 13 October, after RFC karma was requested and granted that morning. The RFC change feed lists an edit at 19:24 UTC, and the header now links the discussion thread. The author opened the discussion at 18:36 UTC. The voting thread reads "tbd", so there is no vote date.

Proposal

Two new global constants in ext/json, accepted in $flags by json_decode() and json_validate():

The flags are independent. Without them, results, error codes and error locations do not change. json_encode() does not change and ignores both flags. Before this RFC, json_validate() accepted only JSON_INVALID_UTF8_IGNORE. Other flags still throw ValueError, and its message would name the three accepted flags.

Comment rules in the RFC:

Trailing-comma rules: [1, 2, 3,] and {"a": 1,} are accepted, but [,], {,}, [1,,], [1,,2] and a top-level 1, stay syntax errors. [1,} gives the same state-mismatch error as [1}. No new error codes are added, nesting depth is unchanged, and a UTF-8 BOM is still a syntax error.

Relation to JSON5, JSONC and JWCC

The RFC does not add JSON5 (single quotes, unquoted keys, hexadecimal numbers, NaN/Infinity). It says JSON_ALLOW_COMMENTS matches the JSONC draft without trailing commas, and that both flags together match JWCC, except that in this RFC a CR alone also ends a line comment.

A single JSON_ALLOW_JSONC flag, suggested by Tim Düsterhus in the pre-RFC thread, is listed under rejected features. The reasons given are that the jsonc.org specification is a draft, it makes trailing commas optional, and the name JSONC has more than one meaning. Later RFCs could add a combined constant if a stable standard appears.

Ballot

Two primary votes, one per flag, each needing a 2/3 majority. The results are independent.

Evidence the RFC cites

These are the author's measurements, not independently reproduced here:

Compatibility and limitations

Discussion

On 13 October Tim Düsterhus replied that he was "not happy, but the rejected [section] is well-argued" and had no other comments. Larry Garfield agreed: "I have no remaining objections to it." Both had raised points in the pre-RFC thread. These are list replies, not votes.

Related