PHP 8.1 deprecated function warning

Created on 24 September 2023, about 1 year ago
Updated 31 July 2024, 5 months ago

Problem/Motivation

When using this module with a rest export view it is possible to trigger a deprecated function warning.

Deprecated function: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\Core\EventSubscriber\ActiveLinkResponseFilter->onResponse() (line 82 of /app/web/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php)

Steps to reproduce

- With PHP 8.1 and either Drupal 9/ CSV Serialization 8.x-2.1 or Drupal 10 / CSV Serialization 3.0.0
- Create a new rest export view with any authentication restriction
- Enable CSV serialization module / as an acceptable format on the view
- Access the view as a user without authorization

The error is being triggered because:

Symfonys RouteSubscriberListener has a priority of 32, so it runs before this modules CsvSubscriber listener
The route subscriber handles the route before the CSV format is added to the request as the CSVSubscriber has not run at this point
As the authentication on the view fails an exception is thrown
The serialization modules DefaultExceptionSubscriber handles the exception via its on4xx method and tries to set the Content-Type header via this code:

// Add the MIME type from the request to send back in the header.
$headers['Content-Type'] = $request->getMimeType($format);

At that point the format is csv and null is returned.

Proposed resolution

I have not found any documentation to suggest this is what custom formats should be doing - and I assume the same issue would be applicable to other modules - but I am adding this here as its where I found the issue.

Update: Having reviewed other serialization providers it appears the more common was is calling registerFormat on the NegotiationMiddleware

Remaining tasks

Review approach

πŸ› Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡³πŸ‡ΏNew Zealand ericgsmith

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024