-
-
Notifications
You must be signed in to change notification settings - Fork 75
Undefined array key, path issue on windows #1129
Copy link
Copy link
Closed
Labels
Description
Hi @theofidry,
I’m encountering an issue when using the inspect command in php-scoper ^0.18.7.
Command:
./vendor/bin/php-scoper inspect -c ./bin-dev/php-scoper/scoper.inc.php dist/inc/WooCommerce/functions-overrides.phpError:
In InspectCommand.php line 125:
Undefined array key "D:/github/mytheme/dist/inc/WooCommerce/functions-overrides.php"
Reference:
https://github.com/humbug/php-scoper/blob/0.18.7/src/Console/Command/InspectCommand.php#L121
What I Found
When inspecting the source code, it looks like the file path keys use different directory separators in different places:
// Debug output of $config->getFilesWithContents()
// This uses backslashes `\`
D:\github\mytheme\olay\dist\inc\WooCommerce\functions-overrides.php =
array(2)
0 =
"D:\github\mytheme\olay\dist\inc\WooCommerce\functions-overrides.php"
1 =
"<?php
...
// Debug output of $filePath
// This uses forward slashes `/`
"D:/github/mytheme/olay/dist/inc/WooCommerce/functions-overrides.php"
This mismatch between \ and / seems to be the reason for the undefined array key error.
Environment
- OS: Windows
- php-scoper: ^0.18.7
- PHP: 8.1
Expected:
inspect should handle path normalization consistently to avoid key mismatches on Windows.
Suggested Fix
Normalizing the $filePath before it’s used resolves the issue:
$filePath = $this->getFilePath($io, $cwd);
// Normalize for Windows
$filePath = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $filePath);Reactions are currently unavailable