I see Symfony2 's Psr4classloader class in the following sentence:
public function register($prepend = false) { spl_autoload_register(array($this, 'loadClass'), true, $prepend); }
The first argument to the Spl_autoload_register function is a string, and I can understand that it is adding a function named string to the AutoLoad stack. But what does this mean by an array?
Reply content:
I see Symfony2 's Psr4classloader class in the following sentence:
public function register($prepend = false) { spl_autoload_register(array($this, 'loadClass'), true, $prepend); }
The first argument to the Spl_autoload_register function is a string, and I can understand that it is adding a function named string to the AutoLoad stack. But what does this mean by an array?
This problem indicates that you do not have a few ways to describe and handle callbacks in PHP.
The is_callable can be processed directly by a series of functions, and the parameter is a string or an array that can locate the call location.
There are several callback types in the callable, the main one is the simple callback type, and the passing of a string is the callback function named after the string. There are two types of incoming arrays: one is a static method callback, and the other is an object method callback. The code of the title is the object method callback, call the $this->loadclass () method of this class, of course, if LoadClass is a static method, change $this to the name of the current class as a string, or so write: spl_autoload_register('MyClass::loadClass', true, $prepend);
. Here is the callback type official address, you can see: Callback callback Type
If it's an array, it's an object in a class,
Equivalent to $this->loadclass