Home>Article>Daily Programming> How to solve the problem of error reporting when nested functions are called in PHP? (Pictures + Videos)

How to solve the problem of error reporting when nested functions are called in PHP? (Pictures + Videos)

藏色散人
藏色散人 Original
2018-09-17 17:30:16 4099browse

For those new to PHP, it may be difficult to learn knowledge about PHP function nesting. For example, when some friends are practicing issues related to PHP function nesting, they will encounter errors when calling internal functions.

Then this article will give you a detailed analysis and introductionabout the processing of special functions and nested functions in PHP.

Below we will give you a detailed explanation through specific code examples.

First we create aPHP nested function codeThe example is as follows:


      

The results of this code we access and test through the browser are as follows:

How to solve the problem of error reporting when nested functions are called in PHP? (Pictures + Videos)

As shown in the figure, an error message that the functionName2 function is not defined appears. How to deal with this situation?

Based on the above code, we will call the functionName1 function. The code is as follows:


      

We will then pass the browser test and the result will be as shown below:

How to solve the problem of error reporting when nested functions are called in PHP? (Pictures + Videos)

At this time, the internal function functionName2 can be called successfully.

So what happens if we call external functionsmultiple times on a page?

Based on the above code, we will call the functionName1 function twice. The code is as follows:

"; functionName2();

The test results of accessing through the browser are as follows:

How to solve the problem of error reporting when nested functions are called in PHP? (Pictures + Videos)

As shown in the figure, an error message appears that the functionName2 function cannot be redefined. How to solve and avoid such errors?

Here we need to use the if judgment statement, then the complete code example is as follows:

"; functionName2();

Finally, the test results we access through the browser are as follows:

How to solve the problem of error reporting when nested functions are called in PHP? (Pictures + Videos)

To sum up, we can draw some important conclusions:

1. When the external function is not called, the internal function is equivalent to not existing, otherwise If you call it directly, the above function is not defined error will occur.

2. When calling multiple external functions, you need to use a judgment statement to declare the nested function, otherwise there will be an error that cannot be redefined.

Note: function_exists() can determine whether the specified function is defined.

If you want to know more about PHP, you can follow the PHP Chinese website

PHP Video Tutorial. Welcome everyone to refer to and study!

The above is the detailed content of How to solve the problem of error reporting when nested functions are called in PHP? (Pictures + Videos). 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