Skip to content

Stdlib: tempnam() prefix length (64) + invalid dir fallback notices parity #4401

Description

@PurHur

Category

stdlib

Problem

tempnam() has several php-src-specific behaviors that should match Zend:

  • Prefix is truncated to a max length (64) in php-src
  • Invalid/non-existing $directory falls back to system temp dir and emits a Notice
  • Type validation and null-byte rejection should match Zend error/exception types

php-src reference

  • Core temp file creation: main/php_open_temporary_file.c
  • tempnam() implementation: ext/standard/file.c
  • Tests:
    • ext/standard/tests/file/tempnam_variation9.phpt (prefix max length)
    • ext/standard/tests/file/tempnam_variation7-win32.phpt (invalid/non-existing dir fallback behavior)
    • ext/standard/tests/file/tempnam_variation4.phpt (null byte handling)

Repro

Save as repro_tempnam_prefix_fallback.php:

<?php

$dir = __DIR__ . '/tempnam-test';
@mkdir($dir);

$prefix = 'begin_' . str_repeat('x', 300) . '_end';
$f = tempnam($dir, $prefix);

echo "basename-len=", strlen(basename($f)), "\n";
unlink($f);

// Invalid dir: should fall back to sys_get_temp_dir() and emit a Notice.
$f2 = tempnam("/definitely/does/not/exist", "pfx");
echo "fallback-dir=", realpath(dirname($f2)) === realpath(sys_get_temp_dir()) ? 'yes' : 'no', "\n";
unlink($f2);

Run in Docker:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_tempnam_prefix_fallback.php
./phpc run repro_tempnam_prefix_fallback.php
# Today: prefix length and/or fallback notice behavior mismatch
'

Scope (this repo)

  • ext/standard temp file logic (prefix truncation, path validation)
  • VM error reporting: Notice emission parity for fallback
  • Compliance PHPT(s) ported from php-src (focus on prefix length + invalid dir fallback)

Done when

  • repro_tempnam_prefix_fallback.php matches Zend under ./phpc run
  • Port the relevant php-src PHPT expectations (prefix length + fallback notice/dir)
  • Null-byte rejection matches php-src (TypeError/ValueError + message close enough)
  • ./script/ci-fast.sh --filter VMTest passes for the added tests

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineimplementation-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