Home  >  Article  >  Backend Development  >  PHP method to detect whether a function exists through function_exists, phpfunction_exists_PHP tutorial

PHP method to detect whether a function exists through function_exists, phpfunction_exists_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:02:461065browse

php method to detect the existence of a function through function_exists, phpfunction_exists

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969497.htmlTechArticlephp method to detect the existence of a function through function_exists, phpfunction_exists This article describes the method of php to detect the existence of a function through function_exists . Share it with everyone for everyone...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn