Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP, possible to call the function from within the same function without specifying function name?

Tags:

function

php

Is it possible to call function within the same function without specifying the function name - e.g by using some sort of magic keyword?

like image 365
vamur Avatar asked Mar 01 '26 13:03

vamur


1 Answers

Yes. The constant __FUNCTION__ gives you a string representation of the current function. (src)

function testMe() {
  print __FUNCTION__;
}

testMe(); // outputs "testMe"

You can then of course use this to call itself:

$func = __FUNCTION__;
$func();
like image 51
Owen Avatar answered Mar 03 '26 01:03

Owen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!