Hi,
[1] How does a Callback Function differ from an ordinary function and a User Defined Function such as strpos(), MyFunction() in PHP?
[2] When should we use them?
Source and Examples: http://php.net/manual/en/function.ob-start.php
Functions, UDFs and Callback Functions in PHP
Moderator: General Moderators
Re: Functions, UDFs and Callback Functions in PHP
A callback function is just an ordinary UDF or a "core" function. The main difference is that a callback function is not likely to be called directly by you. You just pass its name to a function and that function calls it whenever it needs it. Of course the function signature (i.e. arguments, type of arguments, return type) must match the expected callback function signature.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Functions, UDFs and Callback Functions in PHP
To put it another way:
The word callback, as used by the PHP docs to denote the type of an argument like in the ob_start example, is a reference to a callable function or method.
The simplest form of a callback is a string containing the name of the function.
You can also supply a method of an object, in this format: array($object, 'methodname');
And, in PHP 5.3, with the introduction of anonymous functions, you can supply one of those as the value, too.
The callback type is described in the docs here: http://php.net/manual/en/language.pseudo-types.php
The word callback, as used by the PHP docs to denote the type of an argument like in the ob_start example, is a reference to a callable function or method.
The simplest form of a callback is a string containing the name of the function.
You can also supply a method of an object, in this format: array($object, 'methodname');
And, in PHP 5.3, with the introduction of anonymous functions, you can supply one of those as the value, too.
The callback type is described in the docs here: http://php.net/manual/en/language.pseudo-types.php