Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixing namespace unit test failure #1719

Merged
merged 1 commit into from

2 participants

@dongilbert
Collaborator

I found a problem in the JLoader Namespacing feature - if a class is already loaded, the autoloader includes the file again anyways.

I download the latest zip of the platform to make sure I didn't break it locally, and got the same errors. This PR fixes the issue by adding a class_exists($class) check to the loadByNamespace* methods.

@LouisLandry

I feel like you should add a false as the second argument in those class_exists() calls. See: http://php.net/manual/en/function.class-exists.php

Otherwise great catch.

@dongilbert dongilbert Fixing namespace unit test failure
Telling class_exists to not try to autoload the class within the autoload methods
66bbf51
@dongilbert
Collaborator

done

@LouisLandry LouisLandry merged commit d461629 into joomla:staging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 26, 2012
  1. @dongilbert

    Fixing namespace unit test failure

    dongilbert authored
    Telling class_exists to not try to autoload the class within the autoload methods
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 1 deletion.
  1. +19 −1 libraries/loader.php
View
20 libraries/loader.php
@@ -210,7 +210,7 @@ public static function load($class)
$class = strtolower($class);
// If the class already exists do nothing.
- if (class_exists($class))
+ if (class_exists($class, false))
{
return true;
}
@@ -239,6 +239,12 @@ public static function load($class)
*/
public static function loadByNamespaceLowerCase($class)
{
+ // If the class already exists do nothing.
+ if (class_exists($class, false))
+ {
+ return true;
+ }
+
// Get the root namespace name.
$namespace = strstr($class, '\\', true);
@@ -280,6 +286,12 @@ public static function loadByNamespaceLowerCase($class)
*/
public static function loadByNamespaceNaturalCase($class)
{
+ // If the class already exists do nothing.
+ if (class_exists($class, false))
+ {
+ return true;
+ }
+
// Get the root namespace name.
$namespace = strstr($class, '\\', true);
@@ -322,6 +334,12 @@ public static function loadByNamespaceNaturalCase($class)
*/
public static function loadByNamespaceMixedCase($class)
{
+ // If the class already exists do nothing.
+ if (class_exists($class, false))
+ {
+ return true;
+ }
+
// Get the root namespace name.
$namespace = strstr($class, '\\', true);
Something went wrong with that request. Please try again.