Skip to content

Instantly share code, notes, and snippets.

@hx
Last active December 18, 2015 16:19
Show Gist options
  • Save hx/5810427 to your computer and use it in GitHub Desktop.
Save hx/5810427 to your computer and use it in GitHub Desktop.
When you include() a file on a case-insensitive file system, XDebug can get confused about which file you're debugging. This function converts a path with incorrect case to correct case. To test, try var_dump(fixPathCase('/uSr/BiN'));
<?php
function fixPathCase($path) {
if(!file_exists($path)) {
return false;
}
if(file_exists(strtoupper($path)) && file_exists(strtolower($path))) {
$parts = explode('/', $path);
foreach($parts as $k => $i) {
if($i) {
foreach(scandir(dirname(implode('/', array_slice($parts, 0, $k + 1)))) as $file) {
if(!strcasecmp($file, $i)) {
$parts[$k] = $file;
}
}
}
}
return implode('/', $parts);
} else {
return $path;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment