Skip to content

xr.php config file not found when it resides in the same directory as getcwd() #101

@B0bbyD0llar

Description

@B0bbyD0llar

xr.php config file not found when it resides in the same directory as getcwd()

Version: 3.0.3


Description

xr.php is never discovered when it lives in the same directory that getcwd() returns. The config file is only found when it resides in a parent directory of getcwd().

Root cause

In Xr::getConfigFile(), the first iteration concatenates the directory and filename without a directory separator:

// Xr.php, line 134
$configFullPath = $configDirectory . $configName;

getcwd() never returns a trailing separator (on any platform). So the first iteration constructs an invalid path:

getcwd()       → /var/www/project
configFullPath → /var/www/projectxr.php   ✗

The parent-directory traversal on line 140 does append DIRECTORY_SEPARATOR correctly:

$parentDirectory = dirname($configDirectory) . DIRECTORY_SEPARATOR;

This means all iterations after the first one work. The bug only manifests when xr.php is in the same directory as getcwd() — which is exactly the first iteration.

Why it appears to be Windows-only

On Linux/macOS, the typical project structure uses a public/ subdirectory as the web root:

/var/www/project/xr.php      ← config file here
/var/www/project/public/     ← web root, getcwd() points here

The first (broken) iteration looks for /var/www/projectxr.php — not found. Then the parent traversal kicks in, correctly produces /var/www/project/xr.php, and finds it.

On Windows (or any setup where the web root equals the project root), xr.php and getcwd() share the same directory. The broken first iteration is the only one that could find it, so discovery always fails.

Suggested fix

Adding DIRECTORY_SEPARATOR between directory and filename on line 134 would resolve the issue:

// before
$configFullPath = $configDirectory . $configName;

// after
$configFullPath = $configDirectory . DIRECTORY_SEPARATOR . $configName;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions