Steve
Steve

Reputation: 121

Composer breaks exisiting autoload in Codeigniter

I was using Codeigniter to do autoloading for some core classes using the method described here:

http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY

function __autoload($class)
{
 if(strpos($class, 'CI_') !== 0)
 {
  @include_once( APPPATH . 'core/'. $class . EXT );
 }
}

However, once I installed composer (in order to use Eloquent), this funcitonality no longer works. Any ideas?

Thanks!

Upvotes: 6

Views: 1584

Answers (1)

Seldaek
Seldaek

Reputation: 42046

__autoload is the old, deprecated way of doing autoloading, because you can have only one.

You should register your autoloader using spl_autoload_register. e.g.:

function customCIAutoload($class)
{
 if(strpos($class, 'CI_') !== 0)
 {
  @include_once( APPPATH . 'core/'. $class . EXT );
 }
}

spl_autoload_register('customCIAutoload');

This way your autoloader and composer's will coexist happily.

Upvotes: 15

Related Questions