Bug #72389 [Opn->Fbk]: json_decode output date as (int)
| From: | cmb@php.net | Date: | Sun, 12 Jun 2016 13:56:24 +0000 |
| Subject: | Bug #72389 [Opn->Fbk]: json_decode output date as (int) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201548@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
Updated by: cmb@php.net
Reported by: nico at hemk dot es
Summary: json_decode output date as (int)
-Status: Open
+Status: Feedback
Type: Bug
Package: Output Control
Operating System: Linux ubuntu 3.13.0-85-generic
PHP Version: 5.6.22
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> // 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>
Previous Comments:
------------------------------------------------------------------------
[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