Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PHP 8: method_exists(): Argument #1 () must be of type object|string,…
… array given
  • Loading branch information
deleugpn committed Dec 17, 2020
commit f84ebc159f58b4afa68aa36f253ad70f6a3ba07a
4 changes: 4 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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