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

Fatal Error: Type of App\Filters\EventFilter::$filters Must Be Array #8

Closed
Thavarshan opened this issue Apr 10, 2024 · 0 comments · Fixed by #9
Closed

Fatal Error: Type of App\Filters\EventFilter::$filters Must Be Array #8

Thavarshan opened this issue Apr 10, 2024 · 0 comments · Fixed by #9
Assignees
Labels
bug Something isn't working

Comments

@Thavarshan
Copy link
Owner

Thavarshan commented Apr 10, 2024

Issue Description:

When using the EventFilter class that extends Filterable\Filter, a fatal error occurs due to a type mismatch with the property $filters. The error states that $filters must be of type array, as expected by the Filterable\Filter class, but it appears to be set to a different type or not properly initialized as an array.

Error Message:

Symfony\Component\ErrorHandler\Error\FatalError
Type of App\Filters\EventFilter::$filters must be array (as in class Filterable\Filter)

Steps to Reproduce:

  1. Define an EventFilter class that extends Filterable\Filter.
  2. Attempt to apply the filter in a query.
  3. Encounter the fatal error due to a type mismatch with $filters.

Expected Behavior:

The EventFilter class should be able to declare $filters as an array, and the filter functionality should work as intended without any type errors.

Actual Behavior:

A fatal error is thrown because of a type mismatch, preventing the proper use of the filtering functionality.

Code Snippet:

The EventFilter class is defined as follows:

namespace App\Filters;

use Filterable\Filter;
use Illuminate\Database\Eloquent\Builder;

class EventFilter extends Filter
{
    protected $filters = ['filter'];

    protected function filter(string $value): Builder
    {
        return $this->builder->where('column', $value);
    }
}

Possible Solution:

Ensure that $filters is properly typed as an array. If there are default values or initialisations, they should be in an array format. For example:

protected array $filters = ['filter'];

Additional Context:

  • PHP version: 8.3.4
  • Laravel version: 11.3
@Thavarshan Thavarshan added the bug Something isn't working label Apr 10, 2024
@Thavarshan Thavarshan self-assigned this Apr 10, 2024
@Thavarshan Thavarshan linked a pull request Apr 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant