博文

目前显示的是 十二月, 2016的博文

How to understand spl_autoload_register of PHP API

Something about spl_autoload_register from PHP official website: bool   spl_autoload_register  ([  callable   $autoload_function  [,  bool   $throw  = true  [,  bool $prepend  = false  ]]] ) Example: function  my_autoloader ( $class ) {     include  'classes/'  .  $class  .  '.class.php' ; } spl_autoload_register ( 'my_autoloader' ); But how does this work? How does PHP engine know what variable for $class is?  Here is the answer for my question: http://stackoverflow.com/questions/11131238/how-to-use-spl-autoload-register According to Bailey Parker's answer ,  the function you specify is added to a pool of functions that are responsible for autoloading. Your function is appended to this list (so if there were any in the list already, yours will be last). With this, when you do something like this: UnloadedClass :: someFunc ( 'stuff' ); PHP will realize that UnloadedClass hasn't been declared yet. It will then iterate through the SPL