Skip to content

Regression: file_get_contents()/readfile()/file_put_contents() null under strict_types — ValueError not TypeError (ext/standard/file.c) #17063

Closed

Description

@PurHur

Category

stdlib · strict null filename · php-src-strict

Problem

Under declare(strict_types=1), Zend file I/O builtins reject null filenames with TypeError. This compiler raises ValueError (Path cannot be empty) from shared path-string guards — same root cause as #17060.

Repro Zend 8.2 VM (2026-07-07)
declare(strict_types=1); file_get_contents(null); TypeError ValueError: Path cannot be empty
declare(strict_types=1); readfile(null); TypeError ValueError: Path cannot be empty
declare(strict_types=1); file_put_contents(null, 'x'); TypeError ValueError: Path cannot be empty

php-src reference

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r '\''declare(strict_types=1); try { file_get_contents(null); } catch (Throwable $e) { echo get_class($e), "\n"; }'\'''
# VM: ValueError — Zend: TypeError

Done when

Related

Activity

  1. added
    bugSomething isn't working
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 7, 2026
  2. PurHur commented on Jul 7, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run.

  3. PurHur commented on Jul 7, 2026

    @PurHur
    OwnerAuthor

    Cleanup bot note (2026-07-07): Sibling #17060 closed via #17070 — fix pattern is VmStreamPath::coerceNonEmptyPathArgForFrame + JitStreamPath::lowerPath non-empty guard + compliance path_null_strict_typeerror*.phpt. This issue covers file_get_contents/readfile/file_put_contents path arg — same shared path guards; extend the #17070 approach to ext/standard/file.c lowering (not a duplicate of #17060).

  4. PurHur commented on Jul 7, 2026

    @PurHur
    OwnerAuthor

    Merged via #17071.

    Fix: VM execute paths now use VmStreamPath::coerceNonEmptyPathArgForFrame() (file_get_contents, readfile) and VmFilestatArg::filenameArgForFrame() (file_put_contents) so caller strict_types rejects null with TypeError before empty-path ValueError. JIT already routed through JitStringBuiltinArg::lowerPath().

    Verification:

    php bin/vm.php test/repro/maintainer_gap_file_io_null_strict.php
    # file_get_contents=TypeError / readfile=TypeError / file_put_contents=TypeError
    
    vendor/bin/phpunit --filter file_io_null_strict_typeerror
    # OK (4 tests) — VM + JIT compliance
    

    PHP-in-PHP only; no C runtime changes.

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 machinebugSomething isn't workingenhancementNew feature or requestimplementation-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