Skip to content

[Filters] OrderFilter causes deprecation warnings on PHP 8.5 #7752

@burned42

Description

@burned42

API Platform version(s) affected: 4.2.15

Description
I am running on PHP 8.5 and my log fills up with these deprecation messages:

Using null as an array offset is deprecated, use an empty string instead

from vendor/api-platform/doctrine-orm/Filter/OrderFilter.php line 241

The part of the code causing this issue seems to be

$context['filters'][$parameter?->getProperty()]

Where in this case $parameter seems to be null, so it uses null as an array offset, which is deprecated since PHP 8.5:
https://www.php.net/manual/de/migration85.deprecated.php#migration85.deprecated.core.using-null-as-an-array-offset

As every request that uses this order filter triggers a deprecation warning, this fills up my deprecation log file quite a lot.

How to reproduce
This is caused by this ApiFilter attribute using the OrderFilter class:

#[ApiFilter(
    filterClass: OrderFilter::class,
    properties: [
        'createdAt',
        'updatedAt',
    ],
)]

Possible Solution
Verify that the variable used as array offset is not null before trying to access the array offset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions