: This article describes how to use the "_ toString ()" method in php. For more information about PHP tutorials, see. We have mentioned the method for declaring the method name starting with "--" in the class (provided by PHP ),
All methods are automatically called at different times. The "_ toString ()" method is also automatically called,
It is automatically called when the object reference is directly output. we have mentioned that the object reference is a pointer,
For example, in "$ p = new Person ()", $ p is a reference,
We cannot use echo to directly output $ p, which will output an error like "Catchable fatal error: Object of class Person cocould not be converted to string,
If you define the "_ toString ()" method in the class, no errors will be generated when the object is referenced directly,
Instead, the "_ toString ()" method is automatically called to output the characters returned by the "_ toString ()" method,
Therefore, the "_ toString ()" method must have a return value (return statement ).
Function _ toString () {/* is added to the session, and the subscript is stored as code */$ _ SESSION ["code"] = strtoupper ($ this-> checkCode ); // randomly generated characters exist in the session $ this-> outImg (); return '';}
The above describes the use of the [php] "_ toString ()" method, including some content, and hope to help friends who are interested in PHP tutorials.