I have a strange bug where in the following code where the basename() is complete removing the $file:
$files = glob(DIR_APPLICATION . 'controller/module/*.php');
if ($files) {
foreach ($files as $file) {
$extension = basename($file, '.php');
print($file).'<br />';
When debuging, if I add the print() code above the basename it works as expected. If I add it below it completely removing the $file.
What could be the reason for this?
if ($files) {
foreach ($files as $file) {
echo $file . '<br />';
var_dump($file);
echo '<br />';
$extension = basename($file, '.php');
var_dump($file);
echo '<br /><br />';
PHP Version 5.3.10
var_dumpgives different lengths for your strings than the number of human-readable characters it shows (specifically, each length is 6 greater than it should normally be).This means that your pathnames contain multibyte characters, while the documentation for
basenamesaysSo, to solve the problem I suggest:
Use
bin2hexor something similar to see the ordinals of all bytes that make up each path; this will tell you which character(s) in the pathnames are not single-byte. The 6 bytes difference means that it’s probably going to be three characters, so my psychic powers tell me that thewwwmight not be exactly what it looks like.If possible, rename the offending directory to make the paths be single-byte strings and the problem will automatically be solved.
If the above is not possible, then:
a. Find out what encoding the returned paths are in
b. Write your own implementation of
basenamethat uses multibyte string functions, passing them the encoding.