Skip to content

Stdlib: dirname, basename, and realpath for multi-file apps #117

@PurHur

Description

@PurHur

Problem

Multi-file web apps resolve templates with __DIR__ includes (#85) and need path builtins for guards:

$tpl = __DIR__ . '/../templates/home.php';
if (is_file($tpl)) { include $tpl; }

examples/003-MiniWebApp uses __DIR__ only today; dirname / realpath are still missing from ext/standard/Module.php for portable config loading.

Goal

dirname, basename, and realpath with PHP semantics on VM; JIT string paths where arguments are compile-time literals; AOT via libc realpath(3) FFI or VM fallback.

Implementation hints

Builtin VM JIT Registration
dirname Pure string (PHP rules for / and .) Literal fold when arg is const string ext/standard/dirname.php
basename Same Literal fold ext/standard/basename.php
realpath realpath() native or FFI Call libc when path is literal ext/standard/realpath.php
Step Files
1 Add PHP implementations under ext/standard/
2 Register in ext/standard/Module.php
3 JIT handlers in lib/JIT/Builtin/ (or VM-only first)
4 test/compliance/cases/stdlib_dirname.phpt, stdlib_realpath_missing.phpt
5 script/capability-matrix.php rows

Interaction with web stack

Acceptance criteria

./script/ci-fast.sh --filter 'dirname|realpath'
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  php bin/vm.php -r 'echo dirname("/var/www/public/index.php");'
# /var/www/public

PHPT: realpath returns false on missing path (PHP semantics).

Verification

Local/Docker only — not GitHub Actions.

Dependencies

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions