Skip to content

Stdlib: opendir / readdir / closedir / rewinddir — directory iteration (ext/standard/dir.c parity) #3235

Closed

Description

@PurHur

Category

stdlib

Problem

Directory iteration builtins are undefined in this compiler. scandir() exists, but php-src also exposes handle-based directory reading used by frameworks and legacy code:

$dh = opendir('/tmp');
while (($file = readdir($dh)) !== false) { /* … */ }
closedir($dh);

php-src reference

  • ext/standard/dir.c — php_opendir, php_readdir, php_closedir, php_rewinddir
  • ext/standard/basic_functions.c — function registration
  • main/streams/streams.c — php_stream_opendir wrapper

Repro (today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_dump(function_exists(\"opendir\"));"
php bin/vm.php -r "\$d = opendir(\".\"); var_dump(\$d);"
'

Zend PHP: bool(true); returns directory resource
This compiler: Call to undefined function opendir() (lib/VM.php)

Same for readdir, closedir, rewinddir.

Scope (this repo)

Layer Files Notes
VM ext/standard/opendir_.php (new), VmDir.php helper Wrap opendir/readdir/closedir/rewinddir via PHP or C embed
Module ext/standard/Module.php Register four functions
Resource model lib/VM/Resource.php or stream resource type Directory handle distinct from fopen FILE*
JIT lib/JIT/Builtin/ Defer v1 — VM-only acceptable
Tests test/compliance/cases/opendir_readdir.phpt Compare listing subset with scandir on temp dir

v1 semantics: POSIX directory handles; skip dir() OOP wrapper (separate issue if needed).

Done when

  • Repro opens ., reads at least . and .., closes without leak
  • Invalid handle: warning + false (match Zend where applicable)
  • ./script/ci-fast.sh --filter opendir green
  • script/capability-matrix.php lists four functions as VM yes

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter opendir'

Links

Activity

  1. added
    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 May 29, 2026
  2. PurHur commented on Jun 1, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 1, 2026

    @PurHur
    OwnerAuthor

    Merged via #4030.

    Verification
    ```bash
    source script/php-env.sh
    vendor/bin/phpunit --filter 'VMTest.*opendir|AotTest.*opendir'

    OK (3 tests, 7 assertions)

    ```

    AOT smoke: `opendir` + `readdir` loop over `test/fixtures/aot/cases` returns 520 entries.

  4. added a commit that references this issue on Jun 1, 2026
    29622ad
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 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