[php-src] Issue #25108: json_encode() serializes an uninitialized backed property with a setter hook as null

From: Date: Sat, 31 Oct 2026 18:37:58 +0000
Subject: [php-src] Issue #25108: json_encode() serializes an uninitialized backed property with a setter hook as null
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253961@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/25108 Author: JoaoMarcos44 ### Description > AI-assisted report. The explanation was prepared with AI assistance. The reproduction and > outputs below were verified by local execution. > An uninitialized public typed property is omitted by > json_encode(). Adding a setter hook makes the same uninitialized > property appear with a null value. This changes the distinction between an absent field and an > explicit null in serialized data. ```php <?php class Plain { public int $id; } class WithSetter { public int $id { set => $value; } } echo json_encode(new Plain()), "\n"; echo json_encode(new WithSetter()), "\n"; ``` > Actual output: ```text {} {"id":null} ``` > Expected output: ```text {} {} ``` > The hooked-property encoder reads the internal uninitialized sentinel in silent mode and > serializes it instead of omitting the property. Explicitly initialized null values and getters > returning null should remain included. ### PHP Version ```text PHP 8.5.12 (cli) (built: Oct 28 2026 01:23:38) (NTS) Copyright (c) The PHP Group Built by https://github.com/docker-library/php Zend Engine v4.5.12, Copyright (c) Zend Technologies with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies ``` > Also reproduced on PHP 8.7.0-dev at commit > 248c5c45409667b5e69bba38a92c5cc9edd7582a. ### Operating System Debian GNU/Linux 12 (bookworm), Linux container.

« previous php.bugs (#253961) next »