Я обновил PHP с 7.0 до 7.4, и мой код ведет себя иначе, когда я помещаю datatime в json_encode. Я видел эту проблему среди ошибок PHP, но не знаю, как ее исправить. Ошибка 78383 Bugs.php
теперь, если я использую json_decode с datetime, я получаю void array [] даты.
Для этого кода:
$dataTest['text'] = "some text for the example";
$dataTest['date'] = Carbon::now();
$dateEncode = json_encode($dataTest);
$dateDecode = json_decode($dateEncode, TRUE);
dd($dataTest, $dateEncode, $dateDecode);
Я получил:
array:2 [▼
"text" => "some text for the example"
"date" => Carbon {#905 ▼
+"date": "2021-04-14 10:03:28.736535"
+"timezone_type": 3
+"timezone": "Europe/Madrid"
}
]
"{"text":"some text for the example","date":[]}"
array:2 [▼
"text" => "some text for the example"
"date" => []
]
Я могу заставить Carbon быть массивом до json_encode, но это большая работа, чтобы исправить весь мой код. Для этого кода:
$dataTest['text'] = "some text for the example";
$dataTest['date'] = (array)Carbon::now();
$dateEncodeArray = json_encode($dataTest);
$dateDecodeArray = json_decode($dateEncodeArray, TRUE);
dd($dateEncodeArray, $dateDecodeArray );
Я получил:
"{"text":"some text for the example","date":{"date":"2021-04-14 10:09:32.481792","timezone_type":3,"timezone":"Europe\/Madrid"}}"
array:2 [▼
"text" => "some text for the example"
"date" => array:3 [▼
"date" => "2021-04-14 10:09:32.481792"
"timezone_type" => 3
"timezone" => "Europe/Madrid"
]
]
Я использую Carbon 1 (nesbot / carbon 1.32.0 Простое расширение API для DateTime.)
Кто-то с такой же проблемой? Большое спасибо,