Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule validation for JSON throws TypeError on PHP 8.0 #35795

Closed
Joorren opened this issue Jan 6, 2021 · 0 comments
Closed

Rule validation for JSON throws TypeError on PHP 8.0 #35795

Joorren opened this issue Jan 6, 2021 · 0 comments

Comments

@Joorren
Copy link
Contributor

Joorren commented Jan 6, 2021

  • Laravel Version: 8.21.0 (latest)
  • PHP Version: 8.0.0
  • Database Driver & Version: MySQL 5.7

Description:

When using the 'JSON' rule validation in PHP 8, you will get a TypeError when submitting an empty field:

method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given
in vendor/laravel/framework/src/Illuminate/Validation/Concerns/ValidatesAttributes.php:1149

According to php.watch:
Union types are used when they are deemed necessary. For example, method_exists() function accepts either a class name (string) or an object (object). This is enforced as a Union Type of string|object. [...] Prior to PHP 8, it returned false if the provided parameter is not a string or an object, but did not raise any warnings.

Steps To Reproduce:

  1. Create a form with an input field that contains no value (hidden in my case).
  2. Add a json rule for this field (json|required in my case).
  3. Submit the form.
    The website will return method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given
Joorren added a commit to Joorren/framework that referenced this issue Jan 6, 2021
Add an extra is_null check for php 8
Joorren added a commit to Joorren/framework that referenced this issue Jan 6, 2021
Add an extra is_null check for php 8
taylorotwell pushed a commit that referenced this issue Jan 6, 2021
Add an extra is_null check for php 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants