Basic questions: PHP class definition and calling

Source: Internet
Author: User
Basic questions: PHP class definition and calling this post was last edited by bulls5988 at 15:35:23 on

A class is defined in sub. php, which contains a function. Because the returned value must be converted to XML, it cannot be output directly in the function. The following error message is displayed when you call test. php during testing:

Catchable fatal error: Object of class massage_gether cocould not be converted to string in \ xampp \ htdocs \ asxmt_wx \ test. php on line 26


Which of the following steps does I have a problem with the output and call of the class definition?

Sub. php code class massage_gether {function main_menu_test () {// Main menu content $ mytext = 'Welcome to the public service platform of the main store. Please select the number of services you need :'. "\ n ". '(1) Membership card points query '. "\ n ". '(2) shopping mall activity query '. "\ n ". '(4) other services '. "\ n ". 'enter @ to return to the main menu '; return $ mytext ;}}


Index. php code include ("sub. php"); $ shower = new massage_gether (); $ shower-> main_menu_test (); echo $ shower; // This is 26th rows


Reply to discussion (solution)

$ Shower = new massage_gether ();
Echo $ shower-> main_menu_test ();
$ Shower is an instantiated object.

I have been taught. thank you!

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.