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
Ref: #1492, #8948 (enum path operands — separate)
Category
stdlib+compiler· php-src-strictProblem
Passing magic constants
__DIR__/__FILE__directly as the first argument to path stat builtins returnsfalseon 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 usingfile_exists(__DIR__)without a temp variable.Verified maintainer run 2026-06-16.
php-src reference
ext/standard/filestat.c—php_stat()argument coercionZend/zend_compile.c— magic constant folding at compile timeRepro
Commands
Scope (this repo)
lib/Compiler.php)ext/standard/file_exists.php,is_dir.php,VmStatNative.php— ensure path string reaches stat layertest/compliance/cases/stdlib/magic_const_filestat.phptDone when
__DIR__/__FILE__matches variable form onfile_exists,is_dir,is_file,is_link,is_readable,is_writablerealpath(__DIR__)andfiletype(__DIR__)work when inline magic constants are usedRef: #1492, #8948 (enum path operands — separate)