This example describes the __tostring () method in PHP. Share to everyone for your reference, specific as follows:
As we said earlier, the method of declaring "--" the name of the method at the beginning of a class is a method that automatically invokes execution at a given moment in different situations. The "__tostring ()" method is also automatically invoked. Is invoked automatically when the object reference is directly output.
<?php
class testclass{public
$foo;
Public function __construct ($foo) {
$this->foo = $foo;
}
Public Function __tostring () {return
$this->foo;
}
}
$class = new TestClass ("Hello");
echo $class;
? >
This will automatically output "Hello".
More about PHP Interested readers can view the site topics: "PHP object-oriented Program Design Primer", "PHP basic Grammar Introductory Course", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Array" operation Skills Encyclopedia, " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips
I hope this article will help you with the PHP program design.