[PHP] Fix locale-dependent JSON float encoding (#18808) (#25329)
This PR addresses issue #18808 regarding locale-dependent JSON serialization in PHP.
### Problem
When the system environment is set to a locale that uses a comma as a decimal separator (like `de_DE`), `float` and `double` values were being serialized into JSON as `3,14` instead of `3.14`. This produced invalid JSON that could not be parsed by other systems.
### Solution
- Updated php/src/Google/Protobuf/Internal/GPBJsonWire.php to use `sprintf("%.*h", ...)` for formatting values. This ensures that the decimal separator is always a dot (`.`), making the output locale-independent.
- Added a new test case testJsonEncodeFloatLocaleIndependent in php/tests/EncodeDecodeTest.php. This test explicitly sets the locale to `de_DE` to verify that the fix works correctly and produces valid JSON.
### Verification
- [x] Added new regression test.
- [x] Verified that all PHP tests pass locally: `vendor/bin/phpunit php/tests/EncodeDecodeTest.php`
Fixes #18808
Closes #25329
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/25329 from khdkkhdd:18808-php-float-fix 5de303962e25d43c3c5e99b8ae7295008f7527aa
PiperOrigin-RevId: 911348844 D
Dong Kim committed
32d75b6bbc6ff6cc50d29ee8140effa9f7d7e6b5
Parent: 28bef98
Committed by Copybara-Service <copybara-worker@google.com>
on 5/6/2026, 3:23:01 PM