Skip to content

Commit

Permalink
PHP 8: method_exists(): Argument #1 () must be of type object|string,…
Browse files Browse the repository at this point in the history
… array given (#35646)
  • Loading branch information
deleugpn committed Dec 17, 2020
1 parent 94171f0 commit df8fe15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Expand Up @@ -1160,6 +1160,10 @@ public function validateIpv6($attribute, $value)
*/
public function validateJson($attribute, $value)
{
if (is_array($value)) {
return false;
}

if (! is_scalar($value) && ! method_exists($value, '__toString')) {
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Expand Up @@ -1510,6 +1510,10 @@ public function testValidateJson()
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['foo' => '{"name":"John","age":"34"}'], ['foo' => 'json']);
$this->assertTrue($v->passes());

$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['foo' => ['array']], ['foo' => 'json']);
$this->assertFalse($v->passes());
}

public function testValidateBoolean()
Expand Down

0 comments on commit df8fe15

Please sign in to comment.