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

Popular posts from this blog

Ajax Insert Records in Database Tutorial in PHP

Displaying Database data using Class, Object, Constructor, Destructor in PHP MySql

SubQuery with EXISTS and NOT EXISTS in PHP