Jump to content

Can't execute a function


NotionCommotion

Recommended Posts

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 />
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.