Skip to content

Stdlib: DateTime::createFromTimestamp() / DateTimeImmutable::createFromTimestamp() (PHP 8.4, ext/date/php_date.c) #5973

Description

@PurHur

Category

stdlib

Problem

PHP 8.4 adds static factory methods DateTime::createFromTimestamp(int $timestamp): static and DateTimeImmutable::createFromTimestamp(int $timestamp): static. This compiler's VM DateTime builtins (#3072 phase 1) expose __construct, format, getTimestamp, setTimezone only — method_exists(DateTime::class, 'createFromTimestamp') is false.

php-src reference

Repro (PHP 8.4+ reference semantics)

<?php
$dt = DateTime::createFromTimestamp(1700000000);
echo $dt->getTimestamp(), "\n";
$di = DateTimeImmutable::createFromTimestamp(1700000000);
echo $di->getTimestamp(), "\n";
# Reference host PHP 8.4+:
php -r 'var_export(method_exists(DateTime::class,"createFromTimestamp"));'

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_export(method_exists(\"DateTime\",\"createFromTimestamp\"));"'
Check PHP 8.4+ Zend VM today
method_exists(DateTime::class, 'createFromTimestamp') true false
createFromTimestamp(1700000000)->getTimestamp() 1700000000 fatal / missing method

Harness Docker image is PHP 8.2 — gate PHPT with SKIPIF for PHP_VERSION_ID < 80400 until image bumps.

Scope (PHP-in-PHP)

Path Work
lib/VM/Builtin/DateTimeCreateFromTimestamp.php New VM handler
lib/VM/BuiltinClasses.php Register static method on DateTime + DateTimeImmutable
ext/date/ or ext/standard/ Shared timestamp→DateTime logic (reuse DateTimeSupport)
JIT/AOT Phase 1: requiresVmLowering OK; phase 2: LLVM like existing date builtins
Tests test/compliance/cases/stdlib/datetime_create_from_timestamp.phpt

No new runtime/*.c — implement in PHP like #3072.

Done when

  • DateTime::createFromTimestamp() + immutable twin registered and callable on VM
  • Repro prints 1700000000 twice
  • Invalid argument types follow Zend errors from php-src
  • ./script/ci-fast.sh --filter datetime_create_from_timestamp green (with version skip)
  • docs/capabilities-syntax.md row updated via script/capability-syntax.php

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