I understand how it works but why would we practically use this?
<?php
class cat {
public function __toString() {
return "This is a cat\n";
}
}
$toby = new cat;
print $toby;
?>
Isn't this the same as this:
<?php
class cat {
public function random_method() {
echo "This is a cat\n";
}
}
$toby = new cat;
$toby->random_method();
?>
can't we just use any other public method to output any text? Why do we need magic method like this one?