NotionCommotion Posted September 11, 2016 Share Posted September 11, 2016 Why am I not able to execute $container2['hello']($container2)? $container1['hello'] = function ($c) { return 'hello 1 '.print_r($c,1); }; var_dump($container1['hello']($container1)); $app = new \Slim\App(); $container2 = $app->getContainer(); $container2['hello'] = function($c) { return 'hello 2 '.print_r($c,1); }; var_dump($container2['hello']($container2)); string(178) "hello 1 Array ( [hello] => Closure Object ( [parameter] => Array ( [$c] => <required> ) ) ) " <br /> <b>Fatal error</b>: Call to undefined function hello 2 Slim\Container Object ( [defaultSettings:Slim\Container:private] => Array ( [httpVersion] => 1.1 [responseChunkSize] => 4096 [outputBuffering] => append [determineRouteBeforeAppMiddleware] => [displayErrorDetails] => [addContentLengthHeader] => 1 [routerCacheFile] => ) [values:Pimple\Container:private] => Array ( [settings] => Closure Object ( [static] => Array ( [userSettings] => Array ( ) [defaultSettings] => Array ( [httpVersion] => 1.1 [responseChunkSize] => 4096 [outputBuffering] => append in <b>/var/www/html/index.php</b> on line <b>33</b><br /> Quote Link to comment https://forums.phpfreaks.com/topic/302147-cant-execute-a-function/ Share on other sites More sharing options...
kicken Posted September 11, 2016 Share Posted September 11, 2016 Recall my post in one of your other threads In the case of your factory function service, you need to either pass a function that returns the factory function, or use the protect helper method. If you want to define a function as a service, use the protect to prevent Pimple from executing it as the service constructor. Quote Link to comment https://forums.phpfreaks.com/topic/302147-cant-execute-a-function/#findComment-1537389 Share on other sites More sharing options...
NotionCommotion Posted September 12, 2016 Author Share Posted September 12, 2016 Recall my post in one of your other threads If you want to define a function as a service, use the protect to prevent Pimple from executing it as the service constructor. Thanks Kicken, Yes, I do recall your earlier response to one of my other threads! And I am sure your response addresses the particular pimple/slim classes. I am still confused, however, how I can assign a function to two different array elements, and one exists and the other does not. I expect it has to do with those damn magic methods. Quote Link to comment https://forums.phpfreaks.com/topic/302147-cant-execute-a-function/#findComment-1537402 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.