Skip to content

json_encode() of DateTime/DateTimeImmutable returns {} #539

Closed

Description

@samdark

json_encode() of a DateTime or DateTimeImmutable gives {}.

<?php
date_default_timezone_set('UTC');
echo json_encode(new DateTimeImmutable('2024-01-01 00:00:00')), "\n";
echo json_encode(['d' => new DateTime('2024-01-01 00:00:00')]), "\n";

Expected (php):

{"date":"2024-01-01 00:00:00.000000","timezone_type":3,"timezone":"UTC"}
{"d":{"date":"2024-01-01 00:00:00.000000","timezone_type":3,"timezone":"UTC"}}

Actual (manticore compile json.php -o json && ./json):

{}
{"d":{}}

Manticore 0.17.0 (ghcr.io/manticorephp/compiler:latest, image built 2026-10-24, Linux x86_64). PHP reference: 8.5.4.

Activity

  1. added theissue type on Oct 30, 2026
  2. added
    bug
    wrong-answer
    on Oct 30, 2026
  3. blacktrs commented on Oct 30, 2026

    @blacktrs
    Contributor

    The DateTime extension still requires improvements. Looks like DateTime classes are missing JSON serialization methods. This issue should be fixed in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugwrong-answer

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions