In PHP, callback is a function object/reference with type callable. A callback/callable variable can act as a function, object method and a static class method. There are various ways to implement a callback. Some of them are discussed below:
Standard callback: In PHP, functions can be called using call_user_func() function where arguments is the string name of the function to be called.
Static class method callback: Static class methods can be called by using call_user_func() where argument is an array containing the string name of class and the method inside it to be called.
Geeksforgeeks Article Geeksforgeeks Article Parent Geeksforgeeks
Object method callback: Object methods can be called by using call_user_func() where argument is an array containing the object variable and the string name of method to be called. Object method can also be called if they are made invokable using __invoke() function definition. In this case, argument to the call_user_func() function is the object variable itself.
Geeksforgeeks invoke Geeksforgeeks
Closure callback: Closure functions can be made callable by making standard calls or mapping closure function to array of valid arguments given to the closure function using array_map() function where arguments are the closure function and an array of its valid arguments.
Geeksforgeeks GFG Article
- ReactJS | Implementing State & Lifecycle
- Python | Linear search on list or tuples
- HTML | DOM setAttributeNode() Method
- hwclock command in Linux with examples
- BootStrap | Text Utilities (Alignment, Wrapping, Weight etc.)
- BootStrap | Positioning an element with Examples
- Bootstrap | Float utilities with Examples
- Bootstrap | figure class with Examples
- Destructors in C#
- CSS | Specificity
- Bootstrap | Close Icon for dismissing content with Examples
- Containers in Bootstrap with examples
- Bootstrap | Sizing an element with Examples
- CSS | right Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.