Yii Autoload Doesnt Works After Register Another Autoload


I have to register a new autoloader from a library called PagSeguro, but the problem is when i register it, the Yii autloader doesnt find Yii Classes more :(

My code:

// inclui biblioteca do PagSeguro


spl_autoload_unregister(array('YiiBase', 'autoload'));

require_once(Yii::app()->basePath .'/extensions/PagSeguroLibrary/PagSeguroLibrary.php');

spl_autoload_register(array('YiiBase', 'autoload'));

My error:

Can anyone help me?

Did the PagSeguro lib use autoload ?

If it does, you can not use YII API after spl_autoload_unregister. To do that you have to spl_autoload_register . So it’s normal that Yii::app() doen’t work.

You can


$path= Yii::app()->basePath; // the lib path

spl_autoload_unregister(array('YiiBase', 'autoload'));

require_once($path .'/extensions/PagSeguroLibrary/PagSeguroLibrary.php');

........ do the stuff i need and then register YII autoload

spl_autoload_register(array('YiiBase', 'autoload'));

if PagSeguro don’t use autoload, you don’t need to register and unregister the autoload.

Hope it helps.

Some autoloaders allow you to chain another autoloader … they return false on failure so that the next autoloader in the chain can give it a try. That of PHPExcel is this kind, for example.

Other autoloaders don’t allow it … they throw exception on failure and take away the chances from the next one in the chain. Unfortunately, that of Yii is this kind.

So, you’d better check which kind of autoloader PagSeguro has.


For reference: