PHP CALLBACK FUNCTIONS

Sugar babies

PHP CALLBACK FUNCTIONS

  • A callback function (often referred to as just "callback") is a function which is passed as an argument into another function.
  • Any existing function can be used as a callback function. 
  • To use a function as a callback function, pass a string containing the name of the function as the argument of another function.
  • A callback is a function passed as an argument to another function.
  •  This technique allows a function to call another function.
  • A callback function can run after another function has finished.

TYPES OF CALLBACK FUNCTIONS IN PHP :

  • Simple callback.
  • Static class method call
  • Object method callback.
  • Callback using a Closure.

RETURNING A CALLBACK IN PHP :

  • In returning a callback, the called function returns a callback instead of executing it immediately.
  • The calling code where the callback is returned can execute the returned callback immediately, pass it to some other function and so on.

EXAMPLE FOR CALLBACK FUNCTIONS IN PHP :

<?php
//Function to callback
 function my_callback_function()
 {
      echo 'Hello, Rosa!';
}
//PASS my_callback_function INTO call_user_func()
call_user_func('my_callback_function');
?>

 Output :

Hello, Rosa!


Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send