Navigation Menu

Skip to content

Commit

Permalink
[ClassLoader] added support for PHP 5.4 traits
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 22, 2011
1 parent 363057b commit e5a23db
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Expand Up @@ -84,7 +84,7 @@ static public function load($classes, $cacheDir, $name, $autoReload, $adaptive =
$files = array();
$content = '';
foreach ($classes as $class) {
if (!class_exists($class) && !interface_exists($class)) {
if (!class_exists($class) && !interface_exists($class) && function_exists('trait_exists') && !trait_exists($class)) {
throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
}

Expand Down
Expand Up @@ -54,7 +54,7 @@ public function loadClass($class)
if ($file = $this->findFile($class)) {
require $file;

if (!class_exists($class, false) && !interface_exists($class, false)) {
if (!class_exists($class, false) && !interface_exists($class, false) && function_exists('trait_exists') && !trait_exists($class)) {
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}
}
Expand Down

4 comments on commit e5a23db

@shieldo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That condition, surely, won't be true for any version of PHP 5.3, as function_exists('trait_exists') will always be false pre 5.4?

Will submit a PR, anyway.

@shieldo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ach, submitted one, but there's already a PR: #2254. The Symfony community works fast! :)

@staabm
Copy link
Contributor

@staabm staabm commented on e5a23db Oct 3, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found docs about trait_exists on php.net, therefore the question here: wont trait_exists have a second parameter to suppress classloading?

@fabpot
Copy link
Member Author

@fabpot fabpot commented on e5a23db Oct 3, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm: good catch. fixed now.

Please sign in to comment.