diff --git a/src/Str.php b/src/Str.php index 4c25f82..2a52849 100644 --- a/src/Str.php +++ b/src/Str.php @@ -166,10 +166,12 @@ class Str "\xEF\xBE\xA0"], ]; - public function __construct($str) { $this->s = $str; } + public function __construct(string $str) { $this->s = $str; } public function __toString(): string { return $this->s; } public function getString(): string { return $this->s; } + public static function make(string $str): Str { return new self($str); } + public function substr(int $start = 0, int $length = 0): Str { $this->s = \mb_substr($this->s, $start, $length !== 0 ? $length : \mb_strlen($this->s)); diff --git a/tests/StrTest.php b/tests/StrTest.php index 3d1fc0a..747c382 100644 --- a/tests/StrTest.php +++ b/tests/StrTest.php @@ -14,6 +14,9 @@ public function testGetString() $this->assertEquals((string)$s, 'Hello world'); $this->assertEquals((string)$s, $s); $this->assertEquals($s->getString(), 'Hello world'); + + $s = Str::make('Hii'); + $this->assertEquals((string)$s, 'Hii'); } public function testPrefixSuffix()