Skip to content

Stdlib: DateTime::getLastErrors() / DateTimeImmutable::getLastErrors() — parse failure introspection (ext/date/php_datetime.c parity) #4660

Description

@PurHur

Category

stdlib

Problem

When DateTime::createFromFormat() fails, Zend exposes DateTime::getLastErrors() (and the immutable variant) returning warning_count, warnings, error_count, errors. Frameworks use this for user-facing validation messages. This compiler has no static method and no last-error state.

php-src reference

Repro (failure today)

<?php
DateTime::createFromFormat('Y-m-d', 'not-a-date');
$e = DateTime::getLastErrors();
var_dump(is_array($e));
var_dump($e['error_count'] ?? null);
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php'
Runtime Result
Zend PHP 8.x true, error_count >= 1
bin/vm.php Call to undefined method DateTime::getLastErrors()

Scope (this repo)

Area Path
VM state lib/VM/DateTimeSupport.php — thread-local or VM-context last-errors array
Builtins static getLastErrors on DateTime + DateTimeImmutable
Coupling populate from createFromFormat lowering (#4659)
Tests test/compliance/cases/stdlib/datetime_get_last_errors.phpt

Done when

  • After failed createFromFormat, getLastErrors() array keys match Zend subset (warning_count, warnings, error_count, errors)
  • Successful parse clears/resets errors like Zend
  • ./script/ci-fast.sh --filter datetime_get_last_errors green

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