Skip to content

Commit 5588c7a

Browse files
[8.x] Fix casting to string on PHP 8.1 (#39033)
* Fix casting to string on PHP 8.1 * Update tests * Update Str.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 0f5d364 commit 5588c7a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Illuminate/Support/Str.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,15 @@ public static function is($pattern, $value)
253253
{
254254
$patterns = Arr::wrap($pattern);
255255

256+
$value = (string) $value;
257+
256258
if (empty($patterns)) {
257259
return false;
258260
}
259261

260262
foreach ($patterns as $pattern) {
263+
$pattern = (string) $pattern;
264+
261265
// If the given value is an exact match we can of course return true right
262266
// from the beginning. Otherwise, we will translate asterisks and do an
263267
// actual pattern match against the two strings to see if they match.

tests/Support/SupportStrTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ public function testIs()
272272

273273
// empty patterns
274274
$this->assertFalse(Str::is([], 'test'));
275+
276+
$this->assertFalse(Str::is('', 0));
277+
$this->assertFalse(Str::is([null], 0));
278+
$this->assertTrue(Str::is([null], null));
275279
}
276280

277281
/**

0 commit comments

Comments
 (0)