1.2.1193. Throws An Assignement

It is possible to throw an exception, and, in the same time, assign this exception to a variable.

However, the variable will never be used, as the exception is thrown, and any following code is not executed, unless the exception is caught in the same scope.

<?php

    // $e is useful, though not by much
    $e = new() Exception();
    throw $e;

    // $e is useless
    throw $e = new Exception();

?>

1.2.1193.1. Suggestions

  • Drop the assignation

1.2.1193.2. Specs

Short name

Structures/ThrowsAndAssign

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

Very high

Features

throw, assignation

Available in

Entreprise Edition, Community Edition, Exakat Cloud