Typical example: object-oriented graphic calculator

Source: Internet
Author: User
Classic example: the object-oriented graphic calculator is available in the index. php file.
Echo new Form ("index. php"); // Form is a class with a constructor.

Echo new Result ();
What does this mean? isn't new an object created? In this way, the output object can also be used. What is the name of the created object?
Appendix:
The Form class is constructed as follows:
Function _ construct (){
$ This-> action = $ action;
$ This-> shape = isset ($ _ GET ["action"])? $ _ GET ["action"]: "rect ";
}


Reply to discussion (solution)

Echo new Form ("index. php"); returns the instantiated object of Form, which is an object. An error is reported when echo is output. print it using print_r.

Will it be called at the same time? the constructor in Form .. Pass the object containing index. php to $ action.

Yes, but you need to change your constructor to _ construct ($ action?

Yes. What is the name of the instantiated object.

Echo new Result ();
Equivalent
$ P = new Result ();
Echo $ p;

The precondition for this writing is that the _ toString method is defined in the class.
The _ toString method converts an instance of this class into a string. of course, the specific content is determined by you.

Oh... This way... The _ toString () method is followed .. 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.