Home > Backend Development > PHP Tutorial > When a function is defined in a PHP class member method, an error occurs when called recursively? ? ? ? ! ! !

When a function is defined in a PHP class member method, an error occurs when called recursively? ? ? ? ! ! !

PHP中文网
Release: 2016-09-06 08:57:10
Original
1327 people have browsed it

Can I write custom functions in PHP member methods?
I defined a function in a method, but an error was reported when calling it
This is the method that reported the error

When a function is defined in a PHP class member method, an error occurs when called recursively? ? ? ? ! ! !

The error was reported as follows

When a function is defined in a PHP class member method, an error occurs when called recursively? ? ? ? ! ! !

But I have another method where I also wrote the function and performed recursion, But no error was reported.

When a function is defined in a PHP class member method, an error occurs when called recursively? ? ? ? ! ! !

This is the interface for calling these two methods

When a function is defined in a PHP class member method, an error occurs when called recursively? ? ? ? ! ! !

Why is an error reported? Can anyone explain it or have a good solution?



Solution:

1. Look at the error message. Your code has a getTree method and cannot be redefined. Rename or define your getTree to a different namespace.

2.

First remove the function that reports an error. Write a piece of code to check whether the getTree() function already exists:

if (function_exists('getTree')) {
    echo '已经存在getTree()函数'
} else {
    echo '不存在getTree()函数'
}
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template