Skip to content

Enforce import of global functions or using FQN calls #462

Open
@ilnytskyi

Description

Rule

Reason

I used code example from here
https://tideways.com/profiler/blog/compiler-optimized-php-functions
https://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/

If we import or use FQN call for the global function php produces more optimized code.
Also visible via profilers:
SPX:
Selection_578

Same effect with blackfire:

  1. Without import
    Selection_575

  2. with import
    Selection_576

Although the optimization might not be that significant for whole codebase it also helps to specify dependency via use statement.
It also might improve performance of some loops when checks like is_array, ltrim, preg_match etc. are used as PHP would no more execute extra opcode INIT_NS_FCALL_BY_NAME

Also by import or FQN core function for setup:di:compile code we might reduce magento compilation time by a few seconds.

Selection_577

Implementation

Can be taken from here: https://github.com/slevomat/coding-standard/blob/master/doc/namespaces.md#slevomatcodingstandardnamespacesreferenceusednamesonly-

    <rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
        <properties>
            <property name="allowFallbackGlobalFunctions" value="0" />
            <property name="allowFallbackGlobalConstants" value="0" />
        </properties>
    </rule>

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions