7
In C it is possible to use pointers in functions 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;
}
Exit:
Sum: 15
In PHP I was able to reference a function just by keeping its name in a variable and the same variable started pointing to the function. See the example:
<?php
function somar($a, $b)
{
return $a + $b;
}
$s = 'somar';
$r = $s(10, 5);
echo 'Soma: ' . $r;
Exit:
Sum: 15
This way of referencing PHP functions generated me a doubt that is just below.
Doubt
There is a pointer to a function in PHP, if it exists how it works?