Home > Article > Backend Development > PHP method to detect whether a function exists through function_exists, phpfunction_exists_PHP tutorial
The example in this article describes the method of php to detect the existence of a function through function_exists. Share it with everyone for your reference. The specific analysis is as follows:
In PHP, you can use the function_exists() function to detect whether another function exists. You can pass the function name as a string into function_exists to determine whether it still exists
function highlight( $txt ) { return "<sub>$txt</sub>"; } function textWrap( $tag, $txt, $func="" ) { if (function_exists( $func ) ) $txt = $func($txt); return "<$tag>$txt</$tag>\n"; }
Usage examples are as follows:
echo textWrap('i','function exists Demo','highlight'); //输出结果为斜体字的: function exists Demo
I hope this article will be helpful to everyone’s PHP programming design.