Skip to content

php-in-php: VmFsReadNative — pure PHP file_get_contents path without libc open/read FFI (#1492) #8920

Description

@PurHur

Category

php-in-php · stdlib · bootstrap

Problem

VM file reads (file_get_contents, readfile, zip extract, compiler include I/O) funnel through VmFsReadNative — libc open(2)/read(2) via FFI (ext/standard/VmFsReadNative.php). When PHP_COMPILER_DISABLE_FFI=1 (bootstrap/self-host probes), file_get_contents() returns false for readable paths — blocking inventory, capability checks, and M5 fast path without host Zend.

Pure PHP can read regular files via fopen/fread stream wrappers compiled through this pipeline (or thin read(2) syscall stub only when ABI-unavoidable).

php-src reference

Repro

PHP_COMPILER_DISABLE_FFI=1 php bin/vm.php -r '
echo file_get_contents(__FILE__) === false ? "FAIL\n" : "ok\n";
'

Observed: FAIL (FFI path returns false from VmFsReadNative::read()).

Expected: file contents string (match Zend on same path).

Scope

Path Work
ext/standard/VmFsReadNative.php Add VmFsReadPure fallback (PHP streams / compiled fread path)
ext/standard/VmFsWriteNative.php Pair write path if needed for symmetry
Callers file_get_contents.php, VmZipArchive.php, VmString::realpath helpers
Tests test/unit/ext/standard/VmFsReadPureTest.php + repro under PHP_COMPILER_DISABLE_FFI=1

Shrink C/FFI: delete or gate libc read FFI once PHP path is proven; document lines removed.

Done when

  • PHP_COMPILER_DISABLE_FFI=1 php bin/vm.php repro reads __FILE__ successfully
  • Normal FFI builds unchanged (php-src-strict)
  • Bootstrap inventory / spine smoke no longer depends on libc read FFI for committed paths
  • PR notes FFI symbols/lines removed from VmFsReadNative.php

Links

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 / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions