Skip to content

Web: $_SERVER['SCRIPT_FILENAME'] for CGI routing and includes #302

@PurHur

Description

@PurHur

Problem

lib/Web/Superglobals.php sets PHP_SELF and SCRIPT_NAME but not SCRIPT_FILENAME — the absolute path to the script being executed. Front controllers and include resolution in #54 / #210 expect this CGI variable:

$base = dirname($_SERVER['SCRIPT_FILENAME']);
require $base . '/lib/bootstrap.php';

MiniWebApp (#246) and #296 DOCUMENT_ROOT both assume standard CGI meta vars.

Goal

Populate $_SERVER['SCRIPT_FILENAME'] in VM serve, phpc run -q/-p, and AOT runtime refresh to the resolved filesystem path of the entry script (not the request URI).

Implementation hints

  1. Superglobals::populateFromEnvironment() — accept optional $scriptFilename argument; default from SCRIPT_NAME + docroot join when DOCUMENT_ROOT is set (Web: $_SERVER['DOCUMENT_ROOT'] for docroot-relative paths #296).
  2. DevServer — pass realpath($docroot . $path) after index resolution (Web: DevServer default document (index.php) instead of hard-coded example.php #254).
  3. AOT — set in lib/AOT/runtime/superglobals_refresh.c alongside PHP_SELF (see existing set_string_key for SCRIPT_NAME).
  4. Tests — extend test/unit/Web/SuperglobalsTest.php; ServeTest asserts SCRIPT_FILENAME ends with index.php or example.php.

Acceptance criteria

./phpc run -q '' examples/001-SimpleWeb/example.php -r 'echo $_SERVER["SCRIPT_FILENAME"];'

Prints absolute path to example.php (suffix match).

docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  ./script/ci-local.sh --filter Superglobals

New/updated tests pass.

Verification (local / Docker only)

Do not require 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