Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

May be I am wrong, but just #1

Closed
harikt opened this Issue · 2 comments

2 participants

@harikt

Hey,

I was looking into the clone and running tests. May be I am wrong, but just curious to know.

When looking into it I assume it will be the problem with spl_autoload_register(array($this, 'loadClass')); and the way you have the https://github.com/ircmaxell/PSR0-Failure/blob/master/SplClassLoader.php .

I assume adding the Foo namespace to the same classloader and making some variations the classloader works fine.

I have been looking at Aura.Autoload where we can add tests folder and source folder for the same namespace.

https://github.com/auraphp/Aura.Autoload#class-prefix-usage

Or is there something else I am missing or not foreseeing ?

@joksnet

The problem is that spl_autoload_register is a chain, if the first register can't autoload the class, it will try the second one, and so on. SplClassLoader tries to require the file even if this doesn't exists.

diff --git a/SplClassLoader.php b/SplClassLoader.php
index 1fe4c83..3250239 100644
--- a/SplClassLoader.php
+++ b/SplClassLoader.php
@@ -130,7 +130,10 @@ class SplClassLoader
             }
             $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;

-            require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
+            $fullFileName = ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
+            if (is_readable($fullFileName)) {
+                require $fullFileName;
+            }
         }
     }
 }
\ No newline at end of file
@harikt

Thank you @joksnet .

@harikt harikt closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.