In C you can use function pointers to reference other functions, see an example:
int somar(int a, int b)
{
return a + b;
}
int (*sPtr)(int,int);
int main(void)
{
sPtr = &somar;
int r = sPtr(10, 5);
printf("Soma: %i", r);
return 0;
}
Output:
Sum: 15
In PHP I was able to reference a function just by saving its name in a variable and the same variable started to point to the function. See the example:
<?php
function somar($a, $b)
{
return $a + $b;
}
$s = 'somar';
$r = $s(10, 5);
echo 'Soma: ' . $r;
Output:
Sum: 15
This way of referencing PHP functions gave me a question that is just below.
Doubt
Is there a pointer to function in PHP, if it exists how does it work?