What does the keyword “callable” do in PHP












10















To be more exact, the "callable" used in function declaration arguments. like the one below.



function post($pattern, callable $handler) {
$this->routes['post'][$pattern] = $handler;
return $this;
}


How does it benefit us?



why and how do we use it?



Maybe this is very basic for you, however, I've tried searching for it and I was getting no answers. at least, nothing I could understand.



Hoping for a for-dummies answer. I'm new to coding... XD



Edit: Here's a link to where I copied the above piece of code from: link










share|improve this question




















  • 5





    callable is just a type hint for the parameter - have a look at php.net/manual/en/language.types.callable.php for what a callable is.

    – Nigel Ren
    Jan 13 at 6:55
















10















To be more exact, the "callable" used in function declaration arguments. like the one below.



function post($pattern, callable $handler) {
$this->routes['post'][$pattern] = $handler;
return $this;
}


How does it benefit us?



why and how do we use it?



Maybe this is very basic for you, however, I've tried searching for it and I was getting no answers. at least, nothing I could understand.



Hoping for a for-dummies answer. I'm new to coding... XD



Edit: Here's a link to where I copied the above piece of code from: link










share|improve this question




















  • 5





    callable is just a type hint for the parameter - have a look at php.net/manual/en/language.types.callable.php for what a callable is.

    – Nigel Ren
    Jan 13 at 6:55














10












10








10


1






To be more exact, the "callable" used in function declaration arguments. like the one below.



function post($pattern, callable $handler) {
$this->routes['post'][$pattern] = $handler;
return $this;
}


How does it benefit us?



why and how do we use it?



Maybe this is very basic for you, however, I've tried searching for it and I was getting no answers. at least, nothing I could understand.



Hoping for a for-dummies answer. I'm new to coding... XD



Edit: Here's a link to where I copied the above piece of code from: link










share|improve this question
















To be more exact, the "callable" used in function declaration arguments. like the one below.



function post($pattern, callable $handler) {
$this->routes['post'][$pattern] = $handler;
return $this;
}


How does it benefit us?



why and how do we use it?



Maybe this is very basic for you, however, I've tried searching for it and I was getting no answers. at least, nothing I could understand.



Hoping for a for-dummies answer. I'm new to coding... XD



Edit: Here's a link to where I copied the above piece of code from: link







php type-hinting callable function-declaration type-declaration






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 14 at 11:09







S. Goody

















asked Jan 13 at 6:44









S. GoodyS. Goody

566




566








  • 5





    callable is just a type hint for the parameter - have a look at php.net/manual/en/language.types.callable.php for what a callable is.

    – Nigel Ren
    Jan 13 at 6:55














  • 5





    callable is just a type hint for the parameter - have a look at php.net/manual/en/language.types.callable.php for what a callable is.

    – Nigel Ren
    Jan 13 at 6:55








5




5





callable is just a type hint for the parameter - have a look at php.net/manual/en/language.types.callable.php for what a callable is.

– Nigel Ren
Jan 13 at 6:55





callable is just a type hint for the parameter - have a look at php.net/manual/en/language.types.callable.php for what a callable is.

– Nigel Ren
Jan 13 at 6:55












5 Answers
5






active

oldest

votes


















4














The callable type allows us to pass a callback function to the function that is being called. That is, callback function parameters allow the function being called to dynamically call code that we specify in the callable function parameter. This is useful because it allows us to pass dynamic code to be executed to a function.



For example, one might want to call a function and the function accepts a callback function called log, which would log data in a custom way that you want.



I hope that makes sense. For details, see this link.






share|improve this answer
























  • I see, callable was a type and it was used for a type declaration. thanks a lot.

    – S. Goody
    Jan 15 at 7:43



















2














It's a type hinting which tells us this function accepts the parameter $handler as a function, see this example to clarify things:



function helloWorld()
{
echo 'Hello World!';
}
function handle(callable $fn)
{
$fn(); // We know the parameter is callable then we execute the function.
}

handle('helloWorld'); // Outputs: Hello World!


It's a very simple example, But I hope it helps you understand the idea.






share|improve this answer


























  • Callable should be 'callable' even PHP is not case-sensitive, only by convention.

    – boctulus
    Jan 13 at 19:06











  • @boctulus Thanks for the correction, I've edited my answer

    – Shahin
    Jan 13 at 19:57



















1














A callable (callback) function is a function that is called inside another function or used as a parameter of another function



// An example callback function
function my_callback_function() {
echo 'hello world!';
}

// Type 1: Simple callback
call_user_func('my_callback_function');


There are some cases that your function is a template for other functions, in that case, you use parameters for the callable function.




for more information:
http://php.net/manual/en/language.types.callable.php







share|improve this answer































    1














    Here is example use of using a callable as a parameter.



    The wait_do_linebreak function below will sleep for a given time, then call a function with the tailing parameters given, and then echo a line break.



    ...$params packs the tailing parameters into an array called $params. Here it's being used to proxy arguments into the callables.



    At the end of the examples you'll see a native function that takes a callable as a parameter.



    <?php

    function wait_do_linebreak($time, callable $something, ...$params)
    {
    sleep($time);
    call_user_func_array($something, $params);
    echo "n";
    }

    function earth_greeting() {
    echo 'hello earth';
    }

    class Echo_Two
    {
    public function __invoke($baz, $bat)
    {
    echo $baz, " ", $bat;
    }
    }

    class Eat_Static
    {
    static function another()
    {
    echo 'Another example.';
    }
    }

    class Foo
    {
    public function more()
    {
    echo 'And here is another one.';
    }
    }

    wait_do_linebreak(0, 'earth_greeting');
    $my_echo = function($str) {
    echo $str;
    };
    wait_do_linebreak(0, $my_echo, 'hello');
    wait_do_linebreak(0, function() {
    echo "I'm on top of the world.";
    });
    wait_do_linebreak(0, new Echo_Two, 'The', 'Earth');
    wait_do_linebreak(0, ['Eat_Static', 'another']);
    wait_do_linebreak(0, [new Foo, 'more']);

    $array = [
    'jim',
    'bones',
    'spock'
    ];

    $word_contains_o = function (string $str) {
    return strpos($str, 'o') !== false;
    };
    print_r(array_filter($array, $word_contains_o));


    Output:



    hello earth
    hello
    I'm on top of the world.
    The Earth
    Another example.
    And here is another one.
    Array
    (
    [1] => bones
    [2] => spock
    )





    share|improve this answer































      0














      Callable is a data-type.



      note: You can always check whether your variables are of type "callable" by using the built-in is_callable function, giving your variable's handler as its argument.



      The "callable" keyword seen in the code, is used for a "Type declaration", also known as "type hint" in PHP 5. this is used to specify which type of argument or parameter your functions or methods accept. this is done by simply putting the "type hint" or "Type declaration" (i.e. the name of the type, like in this case, "callable") before the parameter names.



      Whenever using "type hints" or "Type declarations" for your function declarations (i.e. when you've specified which types are allowed/accepted), and you're calling them giving parameters of data-types other than those specified as acceptable, an error is generated.



      note: also, class names can be used if you would like to make your function require > an object instantiated from a specific class < for its respective parameter



      -



      References:



      php manual > type-declaration



      php manual > callable type



      -



      I'm new to coding so please correct my mistakes :)






      share|improve this answer








      New contributor




      S. Goody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54166666%2fwhat-does-the-keyword-callable-do-in-php%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        4














        The callable type allows us to pass a callback function to the function that is being called. That is, callback function parameters allow the function being called to dynamically call code that we specify in the callable function parameter. This is useful because it allows us to pass dynamic code to be executed to a function.



        For example, one might want to call a function and the function accepts a callback function called log, which would log data in a custom way that you want.



        I hope that makes sense. For details, see this link.






        share|improve this answer
























        • I see, callable was a type and it was used for a type declaration. thanks a lot.

          – S. Goody
          Jan 15 at 7:43
















        4














        The callable type allows us to pass a callback function to the function that is being called. That is, callback function parameters allow the function being called to dynamically call code that we specify in the callable function parameter. This is useful because it allows us to pass dynamic code to be executed to a function.



        For example, one might want to call a function and the function accepts a callback function called log, which would log data in a custom way that you want.



        I hope that makes sense. For details, see this link.






        share|improve this answer
























        • I see, callable was a type and it was used for a type declaration. thanks a lot.

          – S. Goody
          Jan 15 at 7:43














        4












        4








        4







        The callable type allows us to pass a callback function to the function that is being called. That is, callback function parameters allow the function being called to dynamically call code that we specify in the callable function parameter. This is useful because it allows us to pass dynamic code to be executed to a function.



        For example, one might want to call a function and the function accepts a callback function called log, which would log data in a custom way that you want.



        I hope that makes sense. For details, see this link.






        share|improve this answer













        The callable type allows us to pass a callback function to the function that is being called. That is, callback function parameters allow the function being called to dynamically call code that we specify in the callable function parameter. This is useful because it allows us to pass dynamic code to be executed to a function.



        For example, one might want to call a function and the function accepts a callback function called log, which would log data in a custom way that you want.



        I hope that makes sense. For details, see this link.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 13 at 6:58









        entpnerdentpnerd

        4,90721843




        4,90721843













        • I see, callable was a type and it was used for a type declaration. thanks a lot.

          – S. Goody
          Jan 15 at 7:43



















        • I see, callable was a type and it was used for a type declaration. thanks a lot.

          – S. Goody
          Jan 15 at 7:43

















        I see, callable was a type and it was used for a type declaration. thanks a lot.

        – S. Goody
        Jan 15 at 7:43





        I see, callable was a type and it was used for a type declaration. thanks a lot.

        – S. Goody
        Jan 15 at 7:43













        2














        It's a type hinting which tells us this function accepts the parameter $handler as a function, see this example to clarify things:



        function helloWorld()
        {
        echo 'Hello World!';
        }
        function handle(callable $fn)
        {
        $fn(); // We know the parameter is callable then we execute the function.
        }

        handle('helloWorld'); // Outputs: Hello World!


        It's a very simple example, But I hope it helps you understand the idea.






        share|improve this answer


























        • Callable should be 'callable' even PHP is not case-sensitive, only by convention.

          – boctulus
          Jan 13 at 19:06











        • @boctulus Thanks for the correction, I've edited my answer

          – Shahin
          Jan 13 at 19:57
















        2














        It's a type hinting which tells us this function accepts the parameter $handler as a function, see this example to clarify things:



        function helloWorld()
        {
        echo 'Hello World!';
        }
        function handle(callable $fn)
        {
        $fn(); // We know the parameter is callable then we execute the function.
        }

        handle('helloWorld'); // Outputs: Hello World!


        It's a very simple example, But I hope it helps you understand the idea.






        share|improve this answer


























        • Callable should be 'callable' even PHP is not case-sensitive, only by convention.

          – boctulus
          Jan 13 at 19:06











        • @boctulus Thanks for the correction, I've edited my answer

          – Shahin
          Jan 13 at 19:57














        2












        2








        2







        It's a type hinting which tells us this function accepts the parameter $handler as a function, see this example to clarify things:



        function helloWorld()
        {
        echo 'Hello World!';
        }
        function handle(callable $fn)
        {
        $fn(); // We know the parameter is callable then we execute the function.
        }

        handle('helloWorld'); // Outputs: Hello World!


        It's a very simple example, But I hope it helps you understand the idea.






        share|improve this answer















        It's a type hinting which tells us this function accepts the parameter $handler as a function, see this example to clarify things:



        function helloWorld()
        {
        echo 'Hello World!';
        }
        function handle(callable $fn)
        {
        $fn(); // We know the parameter is callable then we execute the function.
        }

        handle('helloWorld'); // Outputs: Hello World!


        It's a very simple example, But I hope it helps you understand the idea.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 13 at 19:48

























        answered Jan 13 at 7:01









        ShahinShahin

        36616




        36616













        • Callable should be 'callable' even PHP is not case-sensitive, only by convention.

          – boctulus
          Jan 13 at 19:06











        • @boctulus Thanks for the correction, I've edited my answer

          – Shahin
          Jan 13 at 19:57



















        • Callable should be 'callable' even PHP is not case-sensitive, only by convention.

          – boctulus
          Jan 13 at 19:06











        • @boctulus Thanks for the correction, I've edited my answer

          – Shahin
          Jan 13 at 19:57

















        Callable should be 'callable' even PHP is not case-sensitive, only by convention.

        – boctulus
        Jan 13 at 19:06





        Callable should be 'callable' even PHP is not case-sensitive, only by convention.

        – boctulus
        Jan 13 at 19:06













        @boctulus Thanks for the correction, I've edited my answer

        – Shahin
        Jan 13 at 19:57





        @boctulus Thanks for the correction, I've edited my answer

        – Shahin
        Jan 13 at 19:57











        1














        A callable (callback) function is a function that is called inside another function or used as a parameter of another function



        // An example callback function
        function my_callback_function() {
        echo 'hello world!';
        }

        // Type 1: Simple callback
        call_user_func('my_callback_function');


        There are some cases that your function is a template for other functions, in that case, you use parameters for the callable function.




        for more information:
        http://php.net/manual/en/language.types.callable.php







        share|improve this answer




























          1














          A callable (callback) function is a function that is called inside another function or used as a parameter of another function



          // An example callback function
          function my_callback_function() {
          echo 'hello world!';
          }

          // Type 1: Simple callback
          call_user_func('my_callback_function');


          There are some cases that your function is a template for other functions, in that case, you use parameters for the callable function.




          for more information:
          http://php.net/manual/en/language.types.callable.php







          share|improve this answer


























            1












            1








            1







            A callable (callback) function is a function that is called inside another function or used as a parameter of another function



            // An example callback function
            function my_callback_function() {
            echo 'hello world!';
            }

            // Type 1: Simple callback
            call_user_func('my_callback_function');


            There are some cases that your function is a template for other functions, in that case, you use parameters for the callable function.




            for more information:
            http://php.net/manual/en/language.types.callable.php







            share|improve this answer













            A callable (callback) function is a function that is called inside another function or used as a parameter of another function



            // An example callback function
            function my_callback_function() {
            echo 'hello world!';
            }

            // Type 1: Simple callback
            call_user_func('my_callback_function');


            There are some cases that your function is a template for other functions, in that case, you use parameters for the callable function.




            for more information:
            http://php.net/manual/en/language.types.callable.php








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 13 at 6:56









            M.O.AM.O.A

            153




            153























                1














                Here is example use of using a callable as a parameter.



                The wait_do_linebreak function below will sleep for a given time, then call a function with the tailing parameters given, and then echo a line break.



                ...$params packs the tailing parameters into an array called $params. Here it's being used to proxy arguments into the callables.



                At the end of the examples you'll see a native function that takes a callable as a parameter.



                <?php

                function wait_do_linebreak($time, callable $something, ...$params)
                {
                sleep($time);
                call_user_func_array($something, $params);
                echo "n";
                }

                function earth_greeting() {
                echo 'hello earth';
                }

                class Echo_Two
                {
                public function __invoke($baz, $bat)
                {
                echo $baz, " ", $bat;
                }
                }

                class Eat_Static
                {
                static function another()
                {
                echo 'Another example.';
                }
                }

                class Foo
                {
                public function more()
                {
                echo 'And here is another one.';
                }
                }

                wait_do_linebreak(0, 'earth_greeting');
                $my_echo = function($str) {
                echo $str;
                };
                wait_do_linebreak(0, $my_echo, 'hello');
                wait_do_linebreak(0, function() {
                echo "I'm on top of the world.";
                });
                wait_do_linebreak(0, new Echo_Two, 'The', 'Earth');
                wait_do_linebreak(0, ['Eat_Static', 'another']);
                wait_do_linebreak(0, [new Foo, 'more']);

                $array = [
                'jim',
                'bones',
                'spock'
                ];

                $word_contains_o = function (string $str) {
                return strpos($str, 'o') !== false;
                };
                print_r(array_filter($array, $word_contains_o));


                Output:



                hello earth
                hello
                I'm on top of the world.
                The Earth
                Another example.
                And here is another one.
                Array
                (
                [1] => bones
                [2] => spock
                )





                share|improve this answer




























                  1














                  Here is example use of using a callable as a parameter.



                  The wait_do_linebreak function below will sleep for a given time, then call a function with the tailing parameters given, and then echo a line break.



                  ...$params packs the tailing parameters into an array called $params. Here it's being used to proxy arguments into the callables.



                  At the end of the examples you'll see a native function that takes a callable as a parameter.



                  <?php

                  function wait_do_linebreak($time, callable $something, ...$params)
                  {
                  sleep($time);
                  call_user_func_array($something, $params);
                  echo "n";
                  }

                  function earth_greeting() {
                  echo 'hello earth';
                  }

                  class Echo_Two
                  {
                  public function __invoke($baz, $bat)
                  {
                  echo $baz, " ", $bat;
                  }
                  }

                  class Eat_Static
                  {
                  static function another()
                  {
                  echo 'Another example.';
                  }
                  }

                  class Foo
                  {
                  public function more()
                  {
                  echo 'And here is another one.';
                  }
                  }

                  wait_do_linebreak(0, 'earth_greeting');
                  $my_echo = function($str) {
                  echo $str;
                  };
                  wait_do_linebreak(0, $my_echo, 'hello');
                  wait_do_linebreak(0, function() {
                  echo "I'm on top of the world.";
                  });
                  wait_do_linebreak(0, new Echo_Two, 'The', 'Earth');
                  wait_do_linebreak(0, ['Eat_Static', 'another']);
                  wait_do_linebreak(0, [new Foo, 'more']);

                  $array = [
                  'jim',
                  'bones',
                  'spock'
                  ];

                  $word_contains_o = function (string $str) {
                  return strpos($str, 'o') !== false;
                  };
                  print_r(array_filter($array, $word_contains_o));


                  Output:



                  hello earth
                  hello
                  I'm on top of the world.
                  The Earth
                  Another example.
                  And here is another one.
                  Array
                  (
                  [1] => bones
                  [2] => spock
                  )





                  share|improve this answer


























                    1












                    1








                    1







                    Here is example use of using a callable as a parameter.



                    The wait_do_linebreak function below will sleep for a given time, then call a function with the tailing parameters given, and then echo a line break.



                    ...$params packs the tailing parameters into an array called $params. Here it's being used to proxy arguments into the callables.



                    At the end of the examples you'll see a native function that takes a callable as a parameter.



                    <?php

                    function wait_do_linebreak($time, callable $something, ...$params)
                    {
                    sleep($time);
                    call_user_func_array($something, $params);
                    echo "n";
                    }

                    function earth_greeting() {
                    echo 'hello earth';
                    }

                    class Echo_Two
                    {
                    public function __invoke($baz, $bat)
                    {
                    echo $baz, " ", $bat;
                    }
                    }

                    class Eat_Static
                    {
                    static function another()
                    {
                    echo 'Another example.';
                    }
                    }

                    class Foo
                    {
                    public function more()
                    {
                    echo 'And here is another one.';
                    }
                    }

                    wait_do_linebreak(0, 'earth_greeting');
                    $my_echo = function($str) {
                    echo $str;
                    };
                    wait_do_linebreak(0, $my_echo, 'hello');
                    wait_do_linebreak(0, function() {
                    echo "I'm on top of the world.";
                    });
                    wait_do_linebreak(0, new Echo_Two, 'The', 'Earth');
                    wait_do_linebreak(0, ['Eat_Static', 'another']);
                    wait_do_linebreak(0, [new Foo, 'more']);

                    $array = [
                    'jim',
                    'bones',
                    'spock'
                    ];

                    $word_contains_o = function (string $str) {
                    return strpos($str, 'o') !== false;
                    };
                    print_r(array_filter($array, $word_contains_o));


                    Output:



                    hello earth
                    hello
                    I'm on top of the world.
                    The Earth
                    Another example.
                    And here is another one.
                    Array
                    (
                    [1] => bones
                    [2] => spock
                    )





                    share|improve this answer













                    Here is example use of using a callable as a parameter.



                    The wait_do_linebreak function below will sleep for a given time, then call a function with the tailing parameters given, and then echo a line break.



                    ...$params packs the tailing parameters into an array called $params. Here it's being used to proxy arguments into the callables.



                    At the end of the examples you'll see a native function that takes a callable as a parameter.



                    <?php

                    function wait_do_linebreak($time, callable $something, ...$params)
                    {
                    sleep($time);
                    call_user_func_array($something, $params);
                    echo "n";
                    }

                    function earth_greeting() {
                    echo 'hello earth';
                    }

                    class Echo_Two
                    {
                    public function __invoke($baz, $bat)
                    {
                    echo $baz, " ", $bat;
                    }
                    }

                    class Eat_Static
                    {
                    static function another()
                    {
                    echo 'Another example.';
                    }
                    }

                    class Foo
                    {
                    public function more()
                    {
                    echo 'And here is another one.';
                    }
                    }

                    wait_do_linebreak(0, 'earth_greeting');
                    $my_echo = function($str) {
                    echo $str;
                    };
                    wait_do_linebreak(0, $my_echo, 'hello');
                    wait_do_linebreak(0, function() {
                    echo "I'm on top of the world.";
                    });
                    wait_do_linebreak(0, new Echo_Two, 'The', 'Earth');
                    wait_do_linebreak(0, ['Eat_Static', 'another']);
                    wait_do_linebreak(0, [new Foo, 'more']);

                    $array = [
                    'jim',
                    'bones',
                    'spock'
                    ];

                    $word_contains_o = function (string $str) {
                    return strpos($str, 'o') !== false;
                    };
                    print_r(array_filter($array, $word_contains_o));


                    Output:



                    hello earth
                    hello
                    I'm on top of the world.
                    The Earth
                    Another example.
                    And here is another one.
                    Array
                    (
                    [1] => bones
                    [2] => spock
                    )






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 13 at 8:03









                    ProgrockProgrock

                    4,3491820




                    4,3491820























                        0














                        Callable is a data-type.



                        note: You can always check whether your variables are of type "callable" by using the built-in is_callable function, giving your variable's handler as its argument.



                        The "callable" keyword seen in the code, is used for a "Type declaration", also known as "type hint" in PHP 5. this is used to specify which type of argument or parameter your functions or methods accept. this is done by simply putting the "type hint" or "Type declaration" (i.e. the name of the type, like in this case, "callable") before the parameter names.



                        Whenever using "type hints" or "Type declarations" for your function declarations (i.e. when you've specified which types are allowed/accepted), and you're calling them giving parameters of data-types other than those specified as acceptable, an error is generated.



                        note: also, class names can be used if you would like to make your function require > an object instantiated from a specific class < for its respective parameter



                        -



                        References:



                        php manual > type-declaration



                        php manual > callable type



                        -



                        I'm new to coding so please correct my mistakes :)






                        share|improve this answer








                        New contributor




                        S. Goody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.

























                          0














                          Callable is a data-type.



                          note: You can always check whether your variables are of type "callable" by using the built-in is_callable function, giving your variable's handler as its argument.



                          The "callable" keyword seen in the code, is used for a "Type declaration", also known as "type hint" in PHP 5. this is used to specify which type of argument or parameter your functions or methods accept. this is done by simply putting the "type hint" or "Type declaration" (i.e. the name of the type, like in this case, "callable") before the parameter names.



                          Whenever using "type hints" or "Type declarations" for your function declarations (i.e. when you've specified which types are allowed/accepted), and you're calling them giving parameters of data-types other than those specified as acceptable, an error is generated.



                          note: also, class names can be used if you would like to make your function require > an object instantiated from a specific class < for its respective parameter



                          -



                          References:



                          php manual > type-declaration



                          php manual > callable type



                          -



                          I'm new to coding so please correct my mistakes :)






                          share|improve this answer








                          New contributor




                          S. Goody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.























                            0












                            0








                            0







                            Callable is a data-type.



                            note: You can always check whether your variables are of type "callable" by using the built-in is_callable function, giving your variable's handler as its argument.



                            The "callable" keyword seen in the code, is used for a "Type declaration", also known as "type hint" in PHP 5. this is used to specify which type of argument or parameter your functions or methods accept. this is done by simply putting the "type hint" or "Type declaration" (i.e. the name of the type, like in this case, "callable") before the parameter names.



                            Whenever using "type hints" or "Type declarations" for your function declarations (i.e. when you've specified which types are allowed/accepted), and you're calling them giving parameters of data-types other than those specified as acceptable, an error is generated.



                            note: also, class names can be used if you would like to make your function require > an object instantiated from a specific class < for its respective parameter



                            -



                            References:



                            php manual > type-declaration



                            php manual > callable type



                            -



                            I'm new to coding so please correct my mistakes :)






                            share|improve this answer








                            New contributor




                            S. Goody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.










                            Callable is a data-type.



                            note: You can always check whether your variables are of type "callable" by using the built-in is_callable function, giving your variable's handler as its argument.



                            The "callable" keyword seen in the code, is used for a "Type declaration", also known as "type hint" in PHP 5. this is used to specify which type of argument or parameter your functions or methods accept. this is done by simply putting the "type hint" or "Type declaration" (i.e. the name of the type, like in this case, "callable") before the parameter names.



                            Whenever using "type hints" or "Type declarations" for your function declarations (i.e. when you've specified which types are allowed/accepted), and you're calling them giving parameters of data-types other than those specified as acceptable, an error is generated.



                            note: also, class names can be used if you would like to make your function require > an object instantiated from a specific class < for its respective parameter



                            -



                            References:



                            php manual > type-declaration



                            php manual > callable type



                            -



                            I'm new to coding so please correct my mistakes :)







                            share|improve this answer








                            New contributor




                            S. Goody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            share|improve this answer



                            share|improve this answer






                            New contributor




                            S. Goody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            answered Jan 14 at 12:06









                            S. GoodyS. Goody

                            566




                            566




                            New contributor




                            S. Goody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.





                            New contributor





                            S. Goody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






                            S. Goody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54166666%2fwhat-does-the-keyword-callable-do-in-php%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                How to change which sound is reproduced for terminal bell?

                                Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                                Can I use Tabulator js library in my java Spring + Thymeleaf project?