Recursive-Can I write a custom function in the member method of PHP?

Source: Internet
Author: User

Can I write a custom function in the member method of PHP?
I defined the function in a method, but the error was called
This is the method of error.

The error is as follows

But I also have another way to write the function and recursive, but there is no error.

This is the interface that calls these two methods

Why did you get an error? Who can explain, or have a good way to deal with it.

Reply content:

Can I write a custom function in the member method of PHP?
I defined the function in a method, but the error was called
This is the method of error.

The error is as follows

But I also have another way to write the function and recursive, but there is no error.

This is the interface that calls these two methods

Why did you get an error? Who can explain, or have a good way to deal with it.

Why not write your custom function as a member method within a class?

Thank you, you can customize the error here because you have defined the Gettree function elsewhere, the error is that you repeat the definition.

There is also a better choice of PHP closures, probably as follows:

class Test{    public function index(){        $hello_closures = function ($str){            echo $str;        };        $hello_closures("hello , php closures function");    }}

Official documents look here, very easy to understand: Http://php.net/manual/zh/func ...

The error message is already obvious, you cannot define the Gettree function repeatedly, you have already defined it in Labelcontroller

The functions in PHP (not the method of the Class) are global, that is, whether you are defined in the global, or functions defined in the function, are considered global (this is not the same as JS, do not confuse).

PHP does not support function overloading (that is, cannot duplicate the name), so it is not allowed to repeat the function (speaking of overloading, but in the class can be implemented, but the meaning is completely different, it feels like the error handler function, just for the friendly display, personally feel, no eggs).

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.