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 589343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:24:51+00:00 2026-05-13T15:24:51+00:00

I’ve pretty much convinced myself that this is just leaky abstraction rearing it’s ugly

  • 0

I’ve pretty much convinced myself that this is just leaky abstraction rearing it’s ugly head, but I figured before filing a bug report I might probe Stack Overflow for a more insightful answer…

I’m writing a class in PHP to assist autoloading. I hate using the ridiculous, path-oriented class names like the Zend framework uses, so I’ve instead written a class that creates an object to recursively go through a directory and its subdirectories, find all PHP source files, and parse them for class definitions, which are then cached and reused until an autoload fails, which prompts the object to update its index.

I like to use built-in PHP classes wherever possible, so for the indexed paths I’ve used the SplFileInfo class.

Some of the operations required to update the index of classes require that I search the array of SplFileInfo objects my object holds, which is where I have run into a little trouble with using the comparison operator on the SplFileInfo object.

Simply put, searching for any file always returns true. I was a little baffled by it at first, but I’ve tried it on two machines and had a friend try it on his–same result. Seemingly no matter what, when you compare two SplFileInfo objects using the comparison (==) operator, it returns true, even if they point to different files located in completely directories. Whether I use a loop to iterate over each element in the array and compare that way, use in_array(), or array_search(), it always returns true and gives me a reference to a completely different file.

I poked around a little further and found that the identify operator (===) always returns false, even when two SplFileInfo objects point to exactly the same file, initialized with the same path string.

For my code, this means that when I go to update the class index to see if there are any new files, even if a file is new, the indexer object thinks it already knows about that file and moves on. I’ve made this to work by comparing the pathname strings, but that sort of defeats the purpose of using the SplFileInfo class to begin with.

The PHP manual says that extension developers can overload the comparison operators for objects, which is why I sort of assumed that SplFileInfo was smart enough to resolve relative paths and properly compare it with other relative paths, e.g. ./file and file are equal. Turns out, it was only returning true in those instances because it always returns true when comparing two SplFileInfo objects!

This isn’t linked to the code I’m working on. I tried a scratch source file with some new SplFileInfo objects, and compared them. It returns true whether the objects point to different files, the same file, and files that don’t exist.

Since this isn’t the default behavior for comparison operators on objects in PHP, there has to be something in the definition of the class in the extension that is causing this.

Does anyone have any idea why it’s behaving like this, or have any insight?

  • 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-05-13T15:24:52+00:00Added an answer on May 13, 2026 at 3:24 pm

    Andrew,

    I’ve done some experimenting myself with the SPL classes, and surpisingly SplFileInfo is not the only SPL class that exhibits this behaviour. ArrayIterator, for instance, reacts the same way too. I presume more (if not all) SPL classes have this behaviour.

    Although I don’t have an answer as to why this behaviour exists, I do have a workaround for your specific case. You may have come up with this yourself already, but I thought I’ld share it anyway:

    class MyFileInfo extends SplFileInfo
    {
        private $_realPath;
    
        public function __construct( $path )
        {
            parent::__construct( $path );
            $this->_realPath = $this->getRealPath();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.