Laravel displays its views by exposing the object Illuminate\View\Viewas a string. If the object is passed as a string and has a method __toString, PHP will call the method __toStringand use this value from it as the value of the cast.
For example, this program
class Foo
{
public function __toString()
{
return 'I am a foo object';
}
}
$o = new Foo;
echo (string) $o;
displays
I am a foo object.
There's a big caveat to this behavior - due to the granularity of the PHP implementation, you cannot throw an exception in __toString.
, , , , - - . , . , , - PHP-
echo View::make('layouts/blocks/header')->with('sidebar', $sidebar)->with('active', $active);
echo $content;
echo View::make('layouts/blocks/footer');
(, ..), , $sidebar, $content .. . , __toString PHP , , . .