Home>Article>Backend Development> PHP determines whether constants, variables and functions exist example code

PHP determines whether constants, variables and functions exist example code

怪我咯
怪我咯 Original
2017-07-09 09:45:31 1166browse

If you understand the above sentence, then the rest is nonsense.PHP Manualis still very comprehensive. One sentence solves all the problems in my title.

The code is as follows:

if (defined('CONST_NAME')) { //do something }

Variableis detected using isset. Note that the variable is not declared or is assigned a value of NULL when declared, and isset returns FALSE. , such as:

Copy codeThe code is as follows:

if (isset($var_name)) { //do something }

FunctionUse function_exists for detection. Note that the function name to be detected also needs to use quotation marks, such as :

The code is as follows:

if (function_exists('fun_name')) { fun_name(); }

Without further ado, let’s look at an example

The code is as follows:

function_exists determines whether the function exists

The code is as follows:

filter_has_var function

filter_has_var() function checks whether there is a variable of the specified input type.
If successful, return true, otherwise return false.

The code is as follows:

The output is. Input type exists

The above is the detailed content of PHP determines whether constants, variables and functions exist example code. For more information, please follow other related articles on the PHP Chinese website!

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