Use empty string as `escape` for function `str_getcsv`. by rpmoura · Pull Request #7372 · hyperf/hyperf · GitHub
Skip to content

Use empty string as escape for function str_getcsv.#7372

Merged
limingxinleo merged 4 commits into
hyperf:3.2from
rpmoura:fix-validation-rule-parser
Mar 14, 2026
Merged

Use empty string as escape for function str_getcsv.#7372
limingxinleo merged 4 commits into
hyperf:3.2from
rpmoura:fix-validation-rule-parser

Conversation

@rpmoura

@rpmoura rpmoura commented May 4, 2025

Copy link
Copy Markdown
Contributor

Description

This PR fixes an issue related to size rule validation (e.g., min or max) in the hyperf/validation package when running on PHP 8.4.

Hows to Reproduce

class ExampleRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'username' => ['min:6', 'max:255'],
        ];
    }
}

Problem

In PHP 8.4, the default value of the escape parameter in the str_getcsv function is deprecated.
Relying on the default (\) can produce invalid CSV parsing behavior or non-RFC 4180-compliant output, particularly when the escape character is not explicitly defined.

PHP 8.4 Changelog
Relying on the default value of escape is now deprecated.
When escape is set to anything other than an empty string (""), it can result in CSV that is not compliant with RFC 4180 or unable to survive a roundtrip through the PHP CSV functions.
The default value will change in a future version of PHP, no earlier than PHP 9.0.

Solution

🛠️ Code Adjustment
Updated the usage of str_getcsv to explicitly define the escape parameter as an empty string:

// Before
return str_getcsv($parameter);

// After
return str_getcsv($parameter, ',', '"', '');

References

https://www.php.net/manual/en/function.str-getcsv.php
https://php.watch/versions/8.4/csv-functions-escape-parameter

@huangdijia huangdijia requested a review from Copilot May 4, 2025 06:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Files not reviewed (1)
  • src/validation/src/ValidationRuleParser.php: Language not supported

@limingxinleo limingxinleo changed the base branch from master to 3.2 March 14, 2026 15:10
@limingxinleo limingxinleo changed the title Fix use empty string as escape param Use empty string as escape for function str_getcsv. Mar 14, 2026
@limingxinleo limingxinleo merged commit 199339d into hyperf:3.2 Mar 14, 2026
76 of 77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants