Skip to content

Stdlib: json_decode() malformed UTF-8 — JsonException message wrong vs Zend (ext/json/php_json.c) #10518

Closed

Description

@PurHur

Summary

With JSON_THROW_ON_ERROR, decoding invalid UTF-8 should throw JsonException: Malformed UTF-8 characters, possibly incorrectly encoded. This compiler throws JsonException: Syntax error.

php-src reference

  • ext/json/php_json.c — php_json_decode_ex() UTF-8 validation / error mapping

Repro

<?php
declare(strict_types=1);
var_dump(json_decode("\xFF", flags: JSON_THROW_ON_ERROR));

Zend: JsonException: Malformed UTF-8 characters, possibly incorrectly encoded

VM: JsonException: Syntax error

Expected (php-src-strict)

Match Zend exception message (and code if applicable) for invalid UTF-8 input.

Implementation hints

Done when

  • Repro matches Zend message on VM
  • Targeted test under test/compliance/ or unit test

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 21, 2026
  2. PurHur commented on Jun 24, 2026

    @PurHur
    OwnerAuthor

    Maintainer repro update (2026-06-24): On current master the VM no longer throws JsonException: Syntax error — it returns NULL without throwing when JSON_THROW_ON_ERROR is set on malformed UTF-8 (\\xFF). See #11282 + test/repro/maintainer_gap_json_decode_throw_utf8_null.php. Fixing throw path should restore message/code parity described here.

  3. PurHur commented on Jul 4, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-a — starting this run

  4. PurHur commented on Jul 4, 2026

    @PurHur
    OwnerAuthor

    claim released: repro green on master — maintainer_gap_json_decode_utf8.php prints Malformed UTF-8 message + code 5 on VM.

  5. PurHur commented on Jul 13, 2026

    @PurHur
    OwnerAuthor

    Maintainer triage 2026-07-13: json_decode("\xFF", JSON_THROW_ON_ERROR) message matches Zend (Malformed UTF-8…). Closing as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions