You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
json_encode() serializes an uninitialized backed property with a setter hook as null #25108
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.
<?phpclass Plain {
publicint$id;
}
class WithSetter {
publicint$id {
set => $value;
}
}
echojson_encode(newPlain()), "\n";
echojson_encode(newWithSetter()), "\n";
Actual output:
{}
{"id":null}
Expected output:
{}
{}
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
Also reproduced on the lowest actively supported branch, PHP-8.4, at commit dfcc0433fcda7fb732cba8d7ee8c857d23f9a9e7, with debug and ZTS enabled.
PHP 8.4.28-dev (cli) (built: Oct 31 2026 18:38:26) (ZTS DEBUG)
Copyright (c) The PHP Group
Zend Engine v4.4.28-dev, Copyright (c) Zend Technologies
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.
Activity