×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Peter Wendel
Added: Apr 19, 2015 8:35 PM
Modified: Apr 19, 2015 8:36 PM
Views: 29
Setup own class loader in anonymous function directly in the spl_autload_register method.
  1. spl_autoload_register(function($class){
  2.             if(strpos($class,'_')=== false){
  3.                 $cname = '/'.$class.'/'.$class.'.php';
  4.             }else{
  5.                 $xx = explode('_', $class);
  6.                 $cname = '/'.$xx[0].'/'.$class.'.php';
  7.             }
  8.            
  9.             $yy = explode(PATH_SEPARATOR, get_include_path());        
  10.             foreach ($yy as $path) {
  11.                 if(is_file($path.$cname)){
  12.                     include $path.$cname;
  13.                 }
  14.             }
  15.             });