Hướng dẫn callable php
Callbacks can be denoted by the callable type declaration. Some functions like call_user_func() or usort() accept user-defined callback functions as a parameter. Callback functions can not only be simple functions, but also object methods, including static class methods. PassingA PHP function is passed by its name as a string. Any built-in or user-defined function can be used, except language constructs such as: array(), echo, empty(), eval(), exit(), isset(), list(), print or unset(). A method of an instantiated object is passed as an array containing an object at index 0 and the method name at index 1. Accessing protected and private methods from within a class is allowed. Static class methods can also be passed without instantiating an object of that class by either, passing the class name instead of an object at index 0, or passing Apart from common user-defined function, anonymous functions and arrow functions can also be passed to a callback parameter.
Generally, any object implementing __invoke() can also be passed to a callback parameter. Example #1 Callback function examples
B extends A { Example #2 Callback example using a Closure
implode(' ', $new_numbers); The above example will output:
andrewbessa at gmail dot com ¶ 10 years ago
$property = 'Hello World!';
steve at mrclay dot org ¶ 9 years ago
computrius at gmail dot com ¶ 8 years ago
walkIt($val) {
Riikka K ¶ 7 years ago
doStuff() { edanschwartz at gmail dot com ¶ 7 years ago
someAwesomeMethod() { InvisibleSmiley ¶ 1 year ago
bar(callable $c) {}$x = new X; Yzmir Ramirez ¶ 8 years ago
mariano dot REMOVE dot perez dot rodriguez at gmail dot com ¶ 6 years ago
bradyn at NOSPAM dot bradynpoulsen dot com ¶ 6 years ago
doSomethingFancy($arg1) gulaschsuppe2 at gmail dot com ¶ 3 years ago
function callbackFunc() { Daniel Klein ¶ 4 years ago
bar($value) { pawel dot tadeusz dot niedzielski at gmail dot com ¶ 6 years ago
someAwesomeMethod() { whysteepy at gmail dot com ¶ 5 years ago
chechomancr at hotmail dot com ¶ 7 months ago
Example { chris dot rutledge at gmail dot com ¶ 3 years ago
$isInstance = false; Dan J ¶ 4 years ago
|