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!