 PToN join:2001-10-04 Houston, TX | PHP: spl_register_autoload - Symfony questionHello,
I have a question with the UniversalClassLoader.php that ships with Symfony 2.
Their register() looks like:
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
As per PHP docs, the first argument in the call is the function to call, the custom loader, instead of the __autoload that ships with PHP.
In the code above what does "array($this, 'loadClass')" refer to...? I know what $this is and what loadClass is, but i am not clear on what they mean there...
Anyone know why they include the object itself in there..??
Thanks. |
|
|
|
 cdruGo ColtsPremium,MVM join:2003-05-14 Fort Wayne, IN kudos:7 | PHP is not my native language, but I believe the array($this, 'loadClass') refers to a local method loadClass that is within UniversalClassLoader class. |
|
 JAAuldeWeb DeveloperPremium,MVM join:2001-05-09 Williamsport, MD kudos:3 1 edit | reply to PToN cdru is correct. When you call the `register` method on an instance of UniversalClassLoader, that instance's `loadClass` method is passed to `spl_autoload_register()`. |
|
 PToN join:2001-10-04 Houston, TX | reply to PToN Ok.
I know that $this references to itself, but i didnt find any mention of spl_register_autoload() taking an array as the callback param. I only saw its use in implementations, but never understood WTF the array() was doing there when the docs said: " callable $autoload_function "
Thanks. |
|
 JAAuldeWeb DeveloperPremium,MVM join:2001-05-09 Williamsport, MD kudos:3 | A lot of the SPL stuff is documented in a minimal fashion (to put it nicely). Almost any PHP function which can take a string function-name to specify a callback can be given an array to specify a static class method or an object's instance method instead of just a function. -- The Yakabox | My Development Sandbox | LinkedIn Profile |
|
 cdruGo ColtsPremium,MVM join:2003-05-14 Fort Wayne, IN kudos:7 | reply to PToN The second and last user contributed notes on teh spl_autoload_register manual page both address passing in an array. |
|