php.net |  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
Votes:2
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
 [2016-06-12 12:40 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-12 13:56 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2016-06-12 13:56 UTC] 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 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:
> 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?
 [2016-06-13 10:51 UTC] cmb@php.net
-Status: Feedback +Status: Suspended -Assigned To: cmb +Assigned To: remi
 [2016-06-13 10:51 UTC] cmb@php.net
Yes, this info appears to be sufficient. Apperently, there is
json-c involved, and I found a respective PR for the project:
<https://github.com/remicollet/pecl-json-c/pull/27>.

I'm suspending this ticket and assign it to Remi.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 15:01:28 2024 UTC