ok so everyone knows the thing with autoload it doesn't allow you to throw exceptions in the any the autoload function or any function you define as your autoload function.... the only solution i really know of is use eval(). I was wondering what other solutions do you guys use to overcome this inconvenience? is eval the best way?

code example


spl_autoload_register(array('Loader' , 'Load'));

class Loader
{

  function Load($classname)
  {

if(!file_exits($classname)
{

   eval('classname' , $classname , '{}');
   throw new Exception('exception');
}

  }

}

    You can throw Exceptions from __autoload in php 5.3+

    What version are you using?

    (In 8 years of PHP, I have never needed to use eval for anything. It has it's uses, but not many.)

      Write a Reply...