Why is this incorrect?

Source: Internet
Author: User
In this case, I wrote a method in a class to try to call another similar method reverse in the method indexOp.
However, the error message "Fatal error: Call to undefined function reverse () in D: \ WWW \ shop \ control \ index. php on line 12" is displayed.

Of course, the prompt is that the reverse function is not defined,
But I clearly defined it. isn't there anything that doesn't comply with the regulations?


Reply to discussion (solution)

The problem is reverse (substr ($ str, 1). It is not found here.
Self: reverse (substr ($ str, 1 ));

The problem is reverse (substr ($ str, 1). It is not found here.
Self: reverse (substr ($ str, 1 ));


I tried to remove all the reverse functions. if there is only one shell left, no error is reported. but the problem is that I want to use recursion here. Is it hard to say that the class cannot write recursive methods?

Replace self: with $ this->

#1 I have clearly told you why I turned a blind eye to it?

The method becomes a function without scope.

The reason is clear. how can this problem be solved?

The problem is reverse (substr ($ str, 1). It is not found here.
Self: reverse (substr ($ str, 1 ));


Isn't he Writing self: reverse (substr ($ str, 1?


The problem is reverse (substr ($ str, 1). It is not found here.
Self: reverse (substr ($ str, 1 ));


Isn't he Writing self: reverse (substr ($ str, 1?


I tried self: or the above prompt

Paste your code, don't

Recursive call exists in method reverse!

According to the above, there is no problem.

class indexControl{public function reverse($str){if(strlen($str)>0){self::reverse(substr($str,1));echo substr($str,0,1);return;}}public function indexOp(){self::reverse("adfdsfd");}}indexControl::indexOp();

Is it affected by your framework?
In addition, if you just want to put the string upside down, you can use the strrev function without recursion.

You also have a reverse (substr ($ str, 1) method in the reverse method. if this method returns an error, change it to self: reverse (substr ($ str, 1 )); or $ this-> reverse (substr ($ str, 1 );

You also have a reverse (substr ($ str, 1) method in the reverse method. if this method returns an error, change it to self: reverse (substr ($ str, 1 )); or $ this-> reverse (substr ($ str, 1 );


Positive solution !!!!!!!!!!!!!!!!

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.