Skip to content

Latest commit

 

History

History
57 lines (37 loc) · 1.16 KB

NoReturnByReferenceRule.md

File metadata and controls

57 lines (37 loc) · 1.16 KB

Functions\NoReturnByReferenceRule

This rule reports an error when a function returns by reference.

Rationale

Returning by reference lets the caller change state that the function keeps, which makes the code harder to follow. Return a value instead.

Examples

Reported

<?php

declare(strict_types=1);

function &values(): array
{
    static $values = [];

    return $values;
}

Not reported

<?php

declare(strict_types=1);

function values(): array
{
    return [];
}

Parameters

enabled

By default, this rule is enabled, unless you set the allRules parameter to false.

You can set the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noReturnByReference:
			enabled: false

💡 The enabled parameter for noReturnByReference also enables or disables the following rules: