Skip to content

Refactor autoload.php with a constant conditional #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2016

Conversation

siwinski
Copy link
Member

This is up for debate.

Something didn't feel right about the following to me:

if (!class_exists('Fedora\\Autoloader\\Autoload', false)) {
    require_once '/usr/share/php/Fedora/Autoloader/autoload.php';
}

This change allows autoload.php to be fully loaded (even if class Fedora\\Autoloader\\Autoload happened to be loaded already) successfully multiple times without any PHP errors. The constant is just for conditionals and to prevent multiple addPsr4() calls. If we wanted to put the loading conditional in other files, we could use:

if (!defined('FEDORA_AUTOLOADER')) {
    require_once '/usr/share/php/Fedora/Autoloader/autoload.php';
}

Copy link
Collaborator

@remicollet remicollet left a comment

Choose a reason for hiding this comment

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

I'm fine with this, cleaner.

@remicollet
Copy link
Collaborator

Just for memory, the only known case where double include of this file happens: during the php-fedora-autoloder package build (included from phpunit main autoloader + by tests bootstrap).

@siwinski siwinski merged commit 83782c6 into master Oct 26, 2016
@siwinski siwinski deleted the autoload-constant-conditional branch October 27, 2016 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants