I was very convinced that this was just a seeping abstraction, raising his ugly head, but I thought that before reporting the error, I could study Qaru for a more insightful answer ...
I am writing a class in PHP to help autoload. I hate using ridiculous, path-oriented class names such as the Zend framework, so instead I wrote a class that creates an object that recursively looks at the directory and its subdirectories, finds all the PHP source files and parses them for the definition class, which are then cached and reused until autoload succeeds, which causes the object to update its index.
I like to use the built-in PHP classes where possible, so for the indexed paths I used the SplFileInfo class.
Some of the operations needed to update the class index require me to look for an array of SplFileInfo objects that stores my object, in which I encountered little problems when using the comparison operator in the SplFileInfo object.
Simply put, searching for any file always returns true. At first I was a little confused, but I tried it on two machines and asked a friend to try it - the same result. Be that as it may, when you compare two SplFileInfo objects using the comparison operator ( == ), it returns true even if they point to different files located in the full directories. I use a loop to iterate through each element of the array and compare this method using in_array() or array_search() , it always returns true and gives a link to a completely different file.
I chatted a bit and found that the ident ( === ) operator always returns false, even if two SplFileInfo point to the same file, initialized with the same path line.
For my code, this means that when I go to update the class index to see if there are any new files, even if the file is new, the indexer object believes that it already knows about this file and moves on. I made it work by comparing the pathname strings, but this view defeats the purpose of using the SplFileInfo class to SplFileInfo started.
The PHP manual says that extension developers can overload comparison operators for objects, so I believe SplFileInfo is smart enough to allow relative paths and correctly compare it with other relative paths, for example. ./file and file are equal. It turns out that it returned only in these cases, because it always returns true when comparing two SplFileInfo objects!
This is not related to the code I'm working on. I tried the source file from scratch with some new SplFileInfo objects and compared them. It returns true whether the objects point to different files, the same file and files that do not exist.
Since this is not the default behavior for comparison operators for objects in PHP, there must be something in the class definition in the extension that calls this.
Can anyone understand why he behaves this way or understands?