toString Method
<?php
//__toString() is a Magic Method.
//When we try to print any Class's Object as a String at that time __toString() method will
//automatically Call.
//__toString() function will automatically call when we try to print any Object(of Class) as a String.
class Abc
{
public function __toString()
{
return "Can't print Object as a String of Class : " . get_class($this);
}
}
$test = new Abc();
echo $test;
// OUTPUT:
//Can't print Object as a String of Class : Abc
?>
Comments
Post a Comment