Classic example: Object-oriented Graphing calculator

Source: Internet
Author: User
In the index.php file, there are
echo New Form ("index.php"); A form is a class that has a construction method inside it.

echo New Result ();
What does this mean, new is not creating an object? So the output object can also ah. What's the name of the object you created?
Report:
The form class is constructed in the following way:
function __construct () {
$this->action= $action;
$this->shape=isset ($_get["action"])? $_get["Action"]: "rect";
}


Reply to discussion (solution)

echo New Form ("index.php"); An instantiated object of the output form, which is an object. Use the Echo output will be error, to use Print_r (); Printing is only a line.

Will not be called at the same time, the construction method in the form: Pass the object containing the index.php to the $action

Yes, but do you want to change the constructor to __construct ($action)?

Amount, yes. What is the name of the instantiated object?

echo New Result ();
Equivalent
$p = new Result ();
Echo $p;

The precondition for this notation is that the __tostring method is defined in the class
The __tostring method is to convert an instance of this class into a string, and of course what you decide

Oh... So ... There is a __tostring () method behind it: Doshe

  • 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.