SIGN IN SIGN UP

Protocol Buffers - Google's data interchange format

0 0 2 C++

Add option for PHP to emit default values for JSON. (#23985)

This is a reopening of https://github.com/protocolbuffers/protobuf/issues/6035, where it was requested that someone contribute a PR. I chose the option name `EMIT_DEFAULTS` to match the ruby client and existing upd option. I tried to be relatively comprehensive with the tests, but let me know if there's anything stylistically or logically you want changed.

Locally the tests run happily:
```
php % git rev-parse HEAD

7cb3b2d9f60bdffce69c01143ca15c46d2eaa900
php % php -dextension=ext/google/protobuf/modules/protobuf.so -d error_reporting="E_ALL & ~E_DEPRECATED" vendor/bin/phpunit --bootstrap tests/force_c_ext.php tests/EncodeDecodeTest.php
PHPUnit 8.5.26 #StandWithUkraine

...............................................................  63 / 147 ( 42%)
............................................................... 126 / 147 ( 85%)
.....................                                           147 / 147 (100%)

Time: 49 ms, Memory: 6.00 MB

OK (147 tests, 1150 assertions)
```

Closes #23985

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/23985 from SpencerMalone:php-default-value-option 6d8bc7405641c2e46ada64e3cab3fb68d2229160
PiperOrigin-RevId: 821657589
S
Spencer Malone committed
6df6c8aace4d6097100558992b384077811f21e9
Parent: 673ecd2
Committed by Copybara-Service <copybara-worker@google.com> on 10/20/2025, 3:28:16 PM