Skip to content

Regression: json_decode() JSON_THROW_ON_ERROR on malformed UTF-8 — returns NULL, no JsonException (ext/json/php_json.c) #11282

Closed

Description

@PurHur

Category

stdlib · php-src-strict · regression

Problem

With JSON_THROW_ON_ERROR, invalid UTF-8 input must throw JsonException (message Malformed UTF-8 characters, possibly incorrectly encoded, code 5). This compiler’s VM returns NULL and does not throw, so try/catch (JsonException) never runs and scripts continue as if decode succeeded.

Related: #10518 (wrong exception message when throw path exists) — current master behavior is worse (silent NULL). #9032 (general JSON_THROW_ON_ERROR parity).

php-src reference

Repro

test/repro/maintainer_gap_json_decode_throw_utf8_null.php

<?php
declare(strict_types=1);
try {
    json_decode("\xFF", flags: JSON_THROW_ON_ERROR);
    echo "no_exception\n";
} catch (JsonException $e) {
    echo $e->getMessage(), "\n";
    echo $e->getCode(), "\n";
}
$r = json_decode("\xFF", flags: JSON_THROW_ON_ERROR);
echo 'result=', var_export($r, true), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_gap_json_decode_throw_utf8_null.php
php bin/vm.php test/repro/maintainer_gap_json_decode_throw_utf8_null.php'
Step Zend PHP 8.2 This compiler VM
try/catch block prints message + code 5 prints no_exception ❌
bare json_decode JsonException fatal result=NULL, exit 0 ❌

Scope (PHP-in-PHP)

Layer Path
VM ext/standard/VmJson*.php / ext/json/ — enforce UTF-8 validation when JSON_THROW_ON_ERROR set
Tests repro + compliance; close or narrow #10518 once throw path restored

Done when (php-src-strict)

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 24, 2026
  2. PurHur commented on Jun 24, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — batch (issues #11272, #11280, #11282)

  3. PurHur commented on Jun 24, 2026

    @PurHur
    OwnerAuthor

    Verified on current master — json_decode("\xFF", flags: JSON_THROW_ON_ERROR) throws JsonException with code 5 on VM. No code change needed this run.

  4. PurHur commented on Jul 5, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  5. PurHur commented on Jul 5, 2026

    @PurHur
    OwnerAuthor

    claim released: repro green on master — maintainer_gap_json_decode_utf8.php and compliance json_decode_utf8_error.phpt throw JsonException with message + code 5 on VM. Pivoting.

  6. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler Ext — I/O & Crypto — starting this run (pivot from #17679 already green on master)

  7. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Handoff: repro green on master — json_decode("\xFF", flags: JSON_THROW_ON_ERROR) throws JsonException with code 5; compliance json_decode_utf8_error passes. Pivoting to #17721.

  8. PurHur commented on Jul 12, 2026

    @PurHur
    OwnerAuthor

    Stale: verified green on master (2026-07-12, lane-C hygiene run).

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php -r "try { json_decode(\"\\xFF\", true, 512, JSON_THROW_ON_ERROR); } catch (Throwable \$e) { echo get_class(\$e), \"\\n\"; }"
    '

    VM throws JsonException on malformed UTF-8 with JSON_THROW_ON_ERROR — matches Zend.

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