[php-src] Issue #21947: The flag 'JSON_UNESCAPED_LINE_TERMINATORS' seems to be useless

From: Date: Mon, 04 May 2026 15:52:35 +0000
Subject: [php-src] Issue #21947: The flag 'JSON_UNESCAPED_LINE_TERMINATORS' seems to be useless
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-252038@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/21947 Author: JoeHorn ### Description The following code: ```php <?php $strs = [ 'str1' => "Line1\nLine2", 'str2' => "Line1\r\nLine2", 'str3' => 'Line1' . PHP_EOL . 'Line2', ]; foreach ($strs as $k => $v) { echo "** {$k} **" . PHP_EOL . $v . PHP_EOL . PHP_EOL; } echo '** json_encoded **' . PHP_EOL . json_encode( $strs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_LINE_TERMINATORS ) . PHP_EOL . PHP_EOL; ``` Resulted in this output: ``` ** str1 ** Line1 Line2 ** str2 ** Line1 Line2 ** str3 ** Line1 Line2 ** json_encoded ** {"str1":"Line1\nLine2","str2":"Line1\r\nLine2","str3":"Line1\nLine2"} ``` But I expected this output instead: ``` ** str1 ** Line1 Line2 ** str2 ** Line1 Line2 ** str3 ** Line1 Line2 ** json_encoded ** {"str1":"Line1 Line2","str2":"Line1 Line2","str3":"Line1 Line2"} ``` ### PHP Version ```plain PHP 8.3.6 (cli) (built: Mar 20 2026 02:32:55) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.6, Copyright (c) Zend Technologies with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies ``` ### Operating System Ubuntu 24.04

« previous php.bugs (#252038) next »