|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72389 json_decode output date as (int)
Submitted: 2016-06-12 12:40 UTC Modified: 2016-06-13 10:51 UTC
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: nico at hemk dot es Assigned: remi (profile)
Status: Suspended Package: Output Control
PHP Version: 5.6.22 OS: Linux ubuntu 3.13.0-85-generic
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: nico at hemk dot es
New email:
PHP Version: OS:


 [2016-06-12 12:40 UTC] nico at hemk dot es
From manual page:
Server: Linux Ubuntu
PHP Version:
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:
$theDate = '21 June, 2016';

var_dump( $theDate );
// output: string(13) "21 June, 2016"

echo '<hr>';

$myDate = json_decode($theDate, true);
// 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:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-12 13:56 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2016-06-12 13:56 UTC]
> // output: int(2016)

Hm, it seems to me the expected result should be NULL, because
that is a syntax error, see <>.

I assume the different behavior is because your distribution uses
the jsonc extension[1]. Can you please verify that?

[1] <>
 [2016-06-12 19:37 UTC] nico at hemk dot es
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:

// phpinfo():
> json
> json support:	enabled
> json version:	1.3.9
> JSON-C version: (bundled) 0.11

Are there enough information for you?
 [2016-06-13 10:51 UTC]
-Status: Feedback +Status: Suspended -Assigned To: cmb +Assigned To: remi
 [2016-06-13 10:51 UTC]
Yes, this info appears to be sufficient. Apperently, there is
json-c involved, and I found a respective PR for the project:

I'm suspending this ticket and assign it to Remi.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 14 19:01:30 2024 UTC