1.2.368. Don’t Collect Void

When a method has the return type void, there is no need to collect the result. The collected value is always null.

With a void return type, the method is intented to be without return value. This analysis also include methods which are not returning anything, and could be completed with a void returntype.

<?php

function foo() : void {
    // doSomething()
}

// This is useless
$result = foo();

// This is useless. It looks like this is a left over from code refactoring
echo foo();

// No explicitly returned values
function goo() {
    // doSomething()
}

?>

1.2.368.1. Connex PHP features

1.2.368.1.1. Suggestions

  • Move the call to the function to its own expression with a semi-colon.

  • Remove assignations of the result of these methods calls.

  • Do not use these methods as parameters.

1.2.368.1.2. Specs

Short name

Functions/DontUseVoid

Rulesets

All, Analyze, Changed Behavior

Exakat since

2.0.9

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud