Skip to content

False positive trigger of deprecation notice in FilteredStream #78

Closed
@ste93cry

Description

@ste93cry
Q A
Bug? yes
New Feature? no
Version 1.4.1

Actual Behavior

When creating my own custom stream to format data into base64 format (are you interested in merging it into core?) I extended the FilteredStream class. The PHP built-in convert.base64-encode stream filter seems to not accept null as value of the $readFilterOptions and $writeFilterOptions arguments. I had to pass an empty array to work around the following error:

Unable to access built-in filter: stream_filter_append(): unable to create or locate filter "convert.base64-encode"

This fixes the problem, but I then get a deprecation notice saying this:

The $writeFilterOptions argument is deprecated since version 1.5 and will be removed in 2.0.

Expected Behavior

As it seems that not all filters accept null as option of the stream_filter_append function, the deprecation notice should not be triggered when passing an empty array

Steps to Reproduce

Just create a class that extends the FilteredStream class and uses the convert.base64-encode stream filter without overriding the constructor. It will throw an exception when using it, and if constructor is overriden to fix the problem a deprecation notice will be triggered

Possible Solutions

The only solution I can think of is to check not only that the $writeFilterOptions argument is not null but also that it's a non-empty array to trigger the deprecation notice. Something like this:

diff --git a/src/Encoding/FilteredStream.php b/src/Encoding/FilteredStream.php
index a32554b..a516f77 100644
--- a/src/Encoding/FilteredStream.php
+++ b/src/Encoding/FilteredStream.php
@@ -60,7 +60,7 @@ abstract class FilteredStream implements StreamInterface
         $this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions);
         $this->writeFilterCallback = Filter\fun($this->writeFilter(), $writeFilterOptions);
 
-        if (null !== $writeFilterOptions) {
+        if (null !== $writeFilterOptions || (is_array($writeFilterOptions) && !empty($writeFilterOptions))) {
             @trigger_error('The $writeFilterOptions argument is deprecated since version 1.5 and will be removed in 2.0.', E_USER_DEPRECATED);
         }

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