Note that there are some explanatory texts on larger screens.

plurals
  1. POLaravel 4 - Container class: share function & closure logic
    primarykey
    data
    text
    <p>I have a follow-up question to the one discussed here: <a href="https://stackoverflow.com/questions/15758936/laravel-core-method-confusion/17295616#17295616">Laravel core method confusion</a></p> <p>I am in the same situation as driechel (author of question above) has been before, currently getting used to Laravel 4 FW and examining the core. Although a precise answer has been given I still don't understand the logic and what is happening under the hood. So I would very much appreciate a further explanation. I know this might be a duplicate but since I cannot post comments yet I'll give it a shot with a new question. Hope it' ok this way.</p> <p>I have been looking at this from another angle starting at this article: <a href="http://blog.joynag.net/2013/05/facades-in-laravel-4-and-static-methods-resolution/" rel="nofollow noreferrer">http://blog.joynag.net/2013/05/facades-in-laravel-4-and-static-methods-resolution/</a></p> <p>When examining the call <code>File:get()</code> I finally end up at the <strong><em>Container class' share function</em></strong> which is called with this actual parameter <code>share(function() { return new Filesystem; }</code>.</p> <p>What I just can't figure out is the use of <code>$container</code>. Especially at the second occurence within the closure: </p> <p><code>$object = $closure($container);</code></p> <p>Could you please clarify this again? Why is <code>$container</code> passed as a parameter here and what is actually contained in it? As far as I understand <code>$closure</code> at that point holds and executes <code>function() { return new Filesystem; }</code> which has no input parameter.</p> <p>I am lost. Studied this and the PHP anonymous functions/closures now for two days straight and still can't figure it out. I neither understand the syntax of <code>$closure($container)</code> here nor the logic.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload