Bug #72389 [NEW]: json_decode output date as (int)
| From: | nico at hemk dot es | Date: | Sun, 12 Jun 2016 12:40:47 +0000 |
| Subject: | Bug #72389 [NEW]: json_decode output date as (int) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-201547@lists.php.net to get a copy of this message | ||
From: nico at hemk dot es
Operating system: Linux ubuntu 3.13.0-85-generic
PHP version: 5.6.22
Package: Output Control
Bug Type: Bug
Bug description:json_decode output date as (int)
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 bug report at https://bugs.php.net/bug.php?id=72389&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72389&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72389&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72389&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72389&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72389&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72389&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72389&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72389&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72389&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72389&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72389&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72389&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72389&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72389&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72389&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72389&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72389&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72389&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72389&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72389&r=mysqlcfg