What are the uses of __toString
in PHP?
For example I have a function such as (inside a class called person)
public function __construct($id, $name) {
$this->id = $id;
$this->name= $name;
}
and
$person= new person("12","James");
$person->setDescription("Test Description");
$person->setImage("Test Image");
How can I use __toString
to grab this data and print them on one line.
For example: 12 Test Description James Test Image