Skip to content

Stdlib: date_add()/date_sub()/date_modify()/date_diff() — procedural DateTime mutation (ext/date/php_date.c parity) #4604

Description

@PurHur

Category

stdlib

Problem

Zend exposes procedural helpers that mutate or compare DateTime objects in place:

  • date_add(DateTime $object, DateInterval $interval): DateTime
  • date_sub(DateTime $object, DateInterval $interval): DateTime
  • date_modify(DateTime $object, string $modifier): DateTime
  • date_diff(DateTime $baseObject, DateTime $targetObject, bool $absolute = false): DateInterval

This compiler has VM DateTime OOP (#3072) but none of the procedural mutators are registered — function_exists('date_add') is false. Frameworks and legacy code call these instead of $dt->add() / $dt->modify() (which also require #3162 DateInterval).

php-src reference

Repro (failure today)

<?php
declare(strict_types=1);

$dt = new DateTime('2026-06-01 12:00:00', new DateTimeZone('UTC'));
// Requires DateInterval from #3162; use host DateInterval on Zend compare only:
$interval = new DateInterval('P1D');

date_add($dt, $interval);
echo $dt->format('Y-m-d'), "\n";

$dt2 = new DateTime('2026-06-01', new DateTimeZone('UTC'));
date_modify($dt2, '+2 days');
echo $dt2->format('Y-m-d'), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_export(function_exists(\"date_add\")); echo \"\\n\";"
php repro.php
'
Runtime Result
Zend PHP 8.3+ 2026-06-02 then 2026-06-03
bin/vm.php Call to undefined function date_add()

Scope (this repo)

Area Path
VM builtins ext/standard/date_add.php, date_sub.php, date_modify.php, date_diff.php (or ext/date/)
Shared helper extend lib/VM/DateTimeSupport.php — delegate to host \DateTime methods
Registration ext/standard/Module.php
Prerequisite #3162 DateInterval VM class (or host-bridge stub for v1)
Tests test/compliance/cases/stdlib/date_add.phpt, date_diff.phpt
Matrix script/capability-matrix.php

v1: VM-only; mutate in place and return the same object reference like Zend. JIT/AOT defer to #4043 DateTime method lowering.

Done when

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