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
The error was reported as follows
But I have another method where I also wrote the function and performed recursion, But no error was reported.
This is the interface for calling these two methods
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()函数' }