site Search:


 
    All Forums Hot Topics Gallery






how-to block ads


 
Search Topic:
Uniqs:
845
Share Topic
Posting?
Post a:
Post a:
Links: ·How To Get Noticed ·Web Monks FAQ ·Webhosting FAQ ·Posting Code ·How To Post ·Webhosting forum
AuthorAll Replies


PToN

join:2001-10-04
Houston, TX

PHP: spl_register_autoload - Symfony question

Hello,

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.


cdru
Go Colts
Premium,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.



JAAulde
Web Developer
Premium,MVM
join:2001-05-09
Williamsport, MD
kudos:3

1 edit

reply to PToN
cdru See Profile 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.



JAAulde
Web Developer
Premium,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



cdru
Go Colts
Premium,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.


Wednesday, 19-Jun 05:32:32 Terms of Use & Privacy | feedback | contact | Hosting by nac.net - DSL,Hosting & Co-lo
over 13.5 years online © 1999-2013 dslreports.com.
Most commented news this week
Hot Topics