Skip to content

Commit df8fe15

Browse files
authored
PHP 8: method_exists(): Argument #1 () must be of type object|string, array given (#35646)
1 parent 94171f0 commit df8fe15

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,10 @@ public function validateIpv6($attribute, $value)
11601160
*/
11611161
public function validateJson($attribute, $value)
11621162
{
1163+
if (is_array($value)) {
1164+
return false;
1165+
}
1166+
11631167
if (! is_scalar($value) && ! method_exists($value, '__toString')) {
11641168
return false;
11651169
}

tests/Validation/ValidationValidatorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,10 @@ public function testValidateJson()
15101510
$trans = $this->getIlluminateArrayTranslator();
15111511
$v = new Validator($trans, ['foo' => '{"name":"John","age":"34"}'], ['foo' => 'json']);
15121512
$this->assertTrue($v->passes());
1513+
1514+
$trans = $this->getIlluminateArrayTranslator();
1515+
$v = new Validator($trans, ['foo' => ['array']], ['foo' => 'json']);
1516+
$this->assertFalse($v->passes());
15131517
}
15141518

15151519
public function testValidateBoolean()

0 commit comments

Comments
 (0)