autoload - Autoloading Traits in PHP -
autoload - Autoloading Traits in PHP -
is there way me differentiate between traits , classes in autoload function? have folder of classes , folder of traits; nice able like...
spl_autoload_register(function($resource) { if ( /* $resource class */ ) { include 'classes/'.$resource.'.php'; } if ( /* $resource trait */ ) { include 'traits/'.$resource.'.php'; } });
the autoload callback function receives 1 piece of information; symbol name requested. there no way see type of symbol should be.
what register multiple functions in autoload stack, 1 handle classes , other traits, using stream_resolve_include_path() or similar, eg
spl_autoload_register(function($classname) { $filename = stream_resolve_include_path('classes/' . $classname . '.php'); if ($filename !== false) { include $filename; } }); spl_autoload_register(function($traitname) { $filename = stream_resolve_include_path('traits/' . $traitname . '.php'); if ($filename !== false) { include $filename; } }); php autoload traits
Comments
Post a Comment