1$number = 10;
2// To convert this number to a string:
3$numberString = (string)$number;
1$var = 5;
2
3// Inline variable parsing
4echo "I'd like {$var} waffles"; // = "I'd like 5 waffles
5
6// String concatenation
7echo "I'd like ".$var." waffles"; // I'd like 5 waffles
8
9// Explicit cast
10$items = (string)$var; // $items === "5";
11
12// Function call
13$items = strval($var); // $items === "5";
14
1<?php
2class StrValTest
3{
4 public function __toString()
5 {
6 return __CLASS__;
7 }
8}
9
10// Prints 'StrValTest'
11echo strval(new StrValTest);
12?>