diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index 67c4b9b5ddd5..89315546fc88 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -293,13 +293,13 @@ public function doesntEndWith($needles) /** * Determine if the string is an exact match with the given value. * - * @param \Illuminate\Support\Stringable|string $value + * @param BaseStringable|string $value * @return bool */ public function exactly($value) { - if ($value instanceof Stringable) { - $value = $value->toString(); + if ($value instanceof BaseStringable) { + $value = (string) $value; } return $this->value === $value; diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 56dd427dd1da..ce0d2e2c4c4b 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -1477,6 +1477,14 @@ public function testExactly() $this->assertFalse($this->stringable('Foo')->exactly('foo')); $this->assertFalse($this->stringable('[]')->exactly([])); $this->assertFalse($this->stringable('0')->exactly(0)); + $this->assertTrue($this->stringable('foo')->exactly(new class() implements \Stringable + { + public function __toString(): string + { + return 'foo'; + } + })); + $this->assertFalse($this->stringable('foo')->exactly(new class() {})); } public function testToInteger()