我一直在修补PHP学习一些新东西(希望如此),我想知道,在字符串的位置使用这些类是否有任何优点/缺点:
class Str
{
protected $value = "";
public function __construct($string)
{
if (is_string($string)) {
$this->value = $string;
return true;
} else {
return false;
}
}
public function contains($needle)
{
return strpos($this->value, $needle) !== false;
}
public function startsWith($needle)
{
return substr($this->value, 0, strlen($needle)) === $needle;
}
public function endsWith($needle)
{
return substr($this->value, -strlen($needle)) === $needle;
}
public function value()
{
return $this->value;
}
}