1.2.366. Don’t Collect Void

When a method returns 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();

?>

1.2.366.1. Suggestions

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

  • Remove assignation of the result of such calls.

1.2.366.2. Specs

Short name

Functions/DontUseVoid

Rulesets

All, Analyze, IsExt, IsPHP, IsStub

Exakat since

2.0.9

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

void

Available in

Entreprise Edition, Exakat Cloud