Conditionally load PHP class I made 2 custom modules: boutique and paypal. paypal is a dependance of boutique.

I check if paypal is enabled, with the following code.

namespace Drupal\boutique\Form\Multistep;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\paypal\Controller\PaypalController;

abstract class MultistepFormBase extends FormBase {
  protected function saveData() {
    if (\Drupal::moduleHandler()-&gt;moduleExists('paypal')) {
      $test = new PaypalController();
      $test-&gt;setPaiement(10,0,1);
    }

    $this-&gt;deleteStore();
    drupal_set_message($this-&gt;t('The form has been saved.'));
  }

}


All is working good, but use Drupal\paypal\Controller\PaypalController; is always be here; if the paypal module is not present, does it create problems? How can I conditionally use use Drupal\paypal\Controller\PaypalController;` only when the module is installed?
You don't have to prevent anything.

The use is just alias information. It doesn't care if the class that you're aliasing doesn't exist. As long as you don't actually use it, it won't fail.