magento / magento/magento-coding-standard

Is there any reason why function `parse_url` is Discouraged?

Open
#401 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Progress: ready for grooming
Dominant language
PHP
Stars
375
Forks
165
PR merge metrics
No merged PRs in 30d

Description

When I use parse_url() function - phpcs shows me the following error:

 39 | WARNING | The use of function parse_url() is discouraged

Is there any reason why I should not use this function?
I don't see any.

Do I have any alternative functions to use?
It was possible to use \Zend\Uri\Http but it's removed starting from Magento 2.4.1.

Can I somehow remove it from the Discouraged function list using a custom ruleset?
Seems like I can't.
Update: I have disabled it using the following sentence, but not sure whether it right way

    <rule ref="Magento2.Functions.DiscouragedFunction">
        <properties>
            <property name="forbiddenFunctions" type="array">
                <element key="!parse_url" value="null"/>
            </property>
        </properties>
    </rule>

See: https://github.com/magento/magento-coding-standard/blob/develop/Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php#L103

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php at the referenced line and review how forbiddenFunctions is configured. Determine whether the parse_url warning and the shown custom-ruleset override are documented; done means the rationale, alternatives, and supported configuration behavior are clearly recorded.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.