- sprintf: documentation ( source)
<?php
class StringSupported {
protected $value;
public function __construct(string $string) {
$this->value = $string;
}
public function __toString() {
return $this->value;
}
}
class Token {
public function replace($text) {
if (is_object($text)) {
throw new \TypeError("Argument $text expected type string, Object passed");
}
echo sprintf('you passed %s', $text);
}
}
$token = new Token();
$token->replace('bob');
$token->replace(new StringSupported('bess'));