Skip to content

Regression: file_exists()/is_dir()/is_file() with inline __DIR__/__FILE__ return false (magic constant lowering) #9127

Description

@PurHur

Category

stdlib + compiler · php-src-strict

Problem

Passing magic constants __DIR__ / __FILE__ directly as the first argument to path stat builtins returns false on VM, while assigning the same constant to a variable first works. Zend treats both forms identically (true).

This cascades into realpath(), filetype(), and any code using file_exists(__DIR__) without a temp variable.

Verified maintainer run 2026-06-16.

php-src reference

Repro

<?php
declare(strict_types=1);

echo json_encode(file_exists(__DIR__)), "\n";
$p = __DIR__;
echo json_encode(file_exists($p)), "\n";

echo json_encode(is_dir(__DIR__)), "\n";
$d = __DIR__;
echo json_encode(is_dir($d)), "\n";

Commands

source script/php-env.sh
php repro.php
# true / true / true / true

php bin/vm.php repro.php
# false / true / false / true   ← wrong inline form

Scope (this repo)

Layer Path
Compiler magic constant operand lowering for builtin calls (lib/Compiler.php)
VM ext/standard/file_exists.php, is_dir.php, VmStatNative.php — ensure path string reaches stat layer
Tests test/compliance/cases/stdlib/magic_const_filestat.phpt

Done when

  • Inline __DIR__ / __FILE__ matches variable form on file_exists, is_dir, is_file, is_link, is_readable, is_writable
  • realpath(__DIR__) and filetype(__DIR__) work when inline magic constants are used
  • JIT/AOT agree when stat builtins are lowered

Ref: #1492, #8948 (enum path operands — separate)

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:compilerCompiler / CFG / JITarea: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