puiu91
1/7/2016 - 6:44 PM

Closure anonymous function in php

Closure anonymous function in php

<?php 

        // add sessions
        $di->add("session", function() { 
            return new Session(); 
        });

        // add cache
        $di->add("cache", function() { 
            return new Cache(); 
        });

        // add class which will be used in any request
        $di->add("anyTimeCalledClass", new SomeClass());
        
        // example with usage params, and next variables
        $di->add("myName", function($params) use($application) {
              $application->myMethod($params);
        });