Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7891831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:43:04+00:00 2026-06-03T06:43:04+00:00

I have a strange bug where in the following code where the basename() is

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:43:05+00:00Added an answer on June 3, 2026 at 6:43 am

    var_dump gives 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 basename says

    basename() is locale aware, so for it to see the correct basename with
    multibyte character paths, the matching locale must be set using the
    setlocale() function.

    So, to solve the problem I suggest:

    1. Use bin2hex or 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 the www might not be exactly what it looks like.

    2. If possible, rename the offending directory to make the paths be single-byte strings and the problem will automatically be solved.

    3. If the above is not possible, then:

      a. Find out what encoding the returned paths are in

      b. Write your own implementation of basename that uses multibyte string functions, passing them the encoding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange bug. I launch a PHP Unit test Suite. At the
I have a very strange bug, which I believe is caused by some code
I've run into a really weird bug. I have the following code running in
I am encountering a strange bug in my code. I have a rails application
i have this strange bug where... in my application.js file i have //= require
I have a strange bug happening in my script. I have 3 balls on
I have found what appears to be a strange bug with sqlite. I have
I have come across some strange behaviour, and I'm assuming a bug in Firefox,
I've found very strange C# compiler behavior for following code: var p1 = new
I'm getting the following strange looking error. Unexpected PHP error [Use of undefined constant

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.