Bug #72389 [Com]: json_decode output date as (int)

From: Date: Sun, 12 Jun 2016 19:37:47 +0000
Subject: Bug #72389 [Com]: json_decode output date as (int)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201554@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72389&edit=1 ID: 72389 Comment by: nico at hemk dot es Reported by: nico at hemk dot es Summary: json_decode output date as (int) Status: Feedback Type: Bug Package: Output Control Operating System: Linux ubuntu 3.13.0-85-generic PHP Version: 5.6.22 Assigned To: cmb Block user comment: N Private report: N New Comment: How can I verify this? I install a normal linux ubuntu and php version from "add-apt-repository ppa:ondrej/php5-5.6 -y" with php-fpm. $ uname -a > Linux mail 3.13.0-85-generic #129-Ubuntu SMP Thu Mar 17 20:50:15 UTC 2016 x86_64 x86_64 x86_64 > GNU/Linux $ cat /etc/php5/fpm/conf.d/20-json.ini: > extension=json.so // phpinfo(): > json > json support: enabled > json version: 1.3.9 > JSON-C version: (bundled) 0.11 Are there enough information for you? Previous Comments: ------------------------------------------------------------------------ [2016-06-12 13:56:21] cmb@php.net > // output: int(2016) Hm, it seems to me the expected result should be NULL, because that is a syntax error, see <https://3v4l.org/BFvHD>. I assume the different behavior is because your distribution uses the jsonc extension[1]. Can you please verify that? [1] <http://pecl.php.net/package/jsonc> ------------------------------------------------------------------------ [2016-06-12 12:40:44] nico at hemk dot es Description: ------------ --- From manual page: http://www.php.net/function.json-decode --- Server: Linux Ubuntu PHP Version: 5.6.20-1+deb.sury.org~trusty+1 Server API: FPM/FastCGI Virtual Directory Support: disabled I test some date format functions with json_decode. Noticed that the function return after json_decode the date as int. Test script: --------------- <?php $theDate = '21 June, 2016'; var_dump( $theDate ); // output: string(13) "21 June, 2016" echo '<hr>'; $myDate = json_decode($theDate, true); var_dump($myDate); // output: NULL echo '<hr>'; $dt = new DateTime( $theDate ); $myDate = $dt->format('Y-m-d'); var_dump( $myDate ); // output: string(10) "2016-06-21" echo '<hr>'; $dt = new DateTime( $theDate ); $myDate = $dt->format('Y-m-d'); var_dump( json_encode($myDate, true) ); // output: string(12) ""2016-06-21"" echo '<hr>'; // false output? : $dt = new DateTime( $theDate ); $myDate = $dt->format('Y-m-d'); var_dump( json_decode($myDate, true) ); // output: int(2016) ?> Expected result: ---------------- string(12) "2016-06-21" Actual result: -------------- int(2016) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72389&edit=1

« previous php.bugs (#201554) next »