__toString() magic method in oop

<?php

/*The __toString() method is automatically called when an object in PHP5 is converted into a string for the purpose of display or concatenation.*/

class ap
{
private $a;
private $b;
public function ho($a,$b)
{
$this->a = $a;
$this->b = $b;
}
public function __toString()
{
return “values are “.$this->a.” and “.$this->b;
}
}

$o = new ap();
$o->ho(11,21);

echo $o;

?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s