Skip to content

Stdlib: touch() ignores $mtime/$atime — always uses now (ext/standard/filestat.c) #28995

Description

@PurHur

Category

bug · php-src-strict · stdlib touch()

Problem

Zend’s touch($filename, $mtime, $atime) sets both timestamps. The VM returns true but leaves filemtime / fileatime at “now”, ignoring both the 2-arg and 3-arg forms.

Reflection already tracks optional ?int typing separately (#28558); this issue is the behavioral timestamp write.

Verified 2026-08-08 in ./script/docker-exec.sh vs host Zend 8.2.32.

Repro Zend 8.2 VM (2026-08-08)
touch($p, 1600000000, 1599999900) then filemtime / fileatime 1600000000 / 1599999900 current unix time / current unix time
touch($p, 1600000000) (2-arg) filemtime === 1600000000 filemtime stays “now”

php-src reference

PHP implementation target

  • ext/standard/VmFsTouch*.php / FsDirJitHelper::touch — pass through $mtime / $atime to the native touch/utime path instead of always using “now”
  • When $atime is omitted, Zend sets atime from mtime (2-arg); match that
  • No new runtime/*.c beyond thin ABI if a native utime trampoline already exists

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/touch_mtime.php <<'"'"'PHP'"'"'
<?php
$p = tempnam(sys_get_temp_dir(), "pc");
$mtime = 1600000000;
$atime = 1599999900;
touch($p, $mtime, $atime);
echo "mtime_ok=", filemtime($p) === $mtime ? "y" : "n", "\n";
echo "atime_ok=", fileatime($p) === $atime ? "y" : "n", "\n";
unlink($p);
PHP
php /tmp/touch_mtime.php; echo ---; php bin/vm.php /tmp/touch_mtime.php'

Done when

  • 2-arg and 3-arg touch() set filemtime/fileatime like Zend
  • Compliance .phpt under test/compliance/cases/
  • php-src-strict; no php-compiler-strict shortcut

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions