Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 259
Steve Avatar asked Apr 04 '13 02:04

Steve


1 Answers

__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.

like image 185
Seldaek Avatar answered Oct 27 '22 09:10

Seldaek