Skip to content

PHP 8.1 - Deprecated: Constant FILTER_SANITIZE_STRING is deprecated #33

@MircoBabin

Description

@MircoBabin

Php 8.1 issues a deprecation warning when sending an email. This is because of FILTER_SANITIZE_STRING in filterName().

    // OLD
    public function filterName($name)
    {
        $rule = array(
            "\r" => '',
            "\n" => '',
            "\t" => '',
            '"'  => "'",
            '<'  => '[',
            '>'  => ']',
        );
        $filtered = filter_var(
            $name,
            FILTER_SANITIZE_STRING,
            FILTER_FLAG_NO_ENCODE_QUOTES
        );
        return trim(strtr($filtered, $rule));
    }

Changing this function to below solves this:

    // CHANGED
    public function filterName($name)
    {
        $rule = array(
            "\r" => '',
            "\n" => '',
            "\t" => '',
            '"'  => "'",
            '<'  => '[',
            '>'  => ']',
        );
        $filtered = filter_var(
            $name,
            FILTER_UNSAFE_RAW,
            FILTER_FLAG_STRIP_LOW
        );
        return trim(strtr($filtered, $rule));
    }

P.S. Sorry, I am unable to provide a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions