Skip to content

Stdlib: DateTime object identity — instanceof false and instance methods fail (ext/date/php_datetime.c) #5120

Description

@PurHur

Category

stdlib

Problem

new DateTime(...) is partially wired (#3072 closed) but instances are broken at runtime:

  • ($dt instanceof DateTime) is false (Zend: true)
  • $dt->getTimestamp() / $dt->format(...) fail with Method call on non-object

Procedural date() works; OOP DateTime is required for timezone-aware code, sessions, and bootstrap inventory paths that construct DateTime objects.

Verified 2026-06-04 on master:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "
\$d = new DateTime(\"2020-01-01\");
echo (\$d instanceof DateTime) ? \"instanceof_ok\n\" : \"instanceof_fail\n\";
"'
# → instanceof_fail

php-src reference

Repro (failure today)

test/repro-maintainer/datetime_instanceof_methods.php:

<?php
$d = new DateTime('2020-01-01');
echo ($d instanceof DateTime) ? 'instanceof_ok' : 'instanceof_fail', "\n";
echo $d->getTimestamp(), "\n";
echo $d->format('U.u'), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/datetime_instanceof_methods.php
php bin/vm.php test/repro-maintainer/datetime_instanceof_methods.php
'
Engine Output
Zend PHP 8.x instanceof_ok, 1577836800, 1577836800.000000
bin/vm.php instanceof_fail, then method-call fatal

Scope (this repo)

Module Path Notes
Builtin class registry lib/VM/BuiltinClasses.php DateTime must register as builtin with correct ClassEntry identity for instanceof
DateTime VM lib/VM/DateTimeSupport.php, lib/VM/Builtin/DateTime*.php object wrapper + method dispatch
Compiler lib/Compiler.php new DateTime lowering
JIT/AOT lib/JIT/Builtin/StringDateTime.php phase 2: #4043; fix VM identity first
Tests test/compliance/cases/stdlib/datetime_instanceof_methods.phpt add if missing
Matrix script/capability-syntax.php DateTime row

PHP-in-PHP: keep parse/format in PHP/VM helpers; host date extension acceptable for v1 (same as #3072).

Done when

  • ($d instanceof DateTime) is true for new DateTime(...) on VM
  • $d->getTimestamp(), $d->format('U.u'), $d->setTimezone(new DateTimeZone('UTC')) work without "Method call on non-object"
  • Repro script passes under php bin/vm.php
  • ./script/ci-fast.sh --filter datetime_instanceof green
  • docs/capabilities-syntax.md DateTime row accurate (VM ✅; JIT defer Stdlib: DateTime / DateTimeZone — JIT/AOT method lowering (phase 2 of #3072) #4043)

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter datetime_instanceof'

Related

Activity

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

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions