1.2.267. Could Be Self

Mark arguments, return types and properties that can be set to self. This applies only to methods.

This analysis works when typehints have already been configured.

<?php

class x {
    // Accept a x object as input
    function foo(x $b) : x {
        // Returns a x object
        return $b;
    }
}

?>

1.2.267.1. Suggestions

  • Add self typehint to the code.

  • Add the literal class/type typehint to the code.

1.2.267.2. Specs

Short name

Typehints/CouldBeSelf

Rulesets

All, Typechecks

Exakat since

2.1.2

PHP Version

All

Severity

Major

Time To Fix

Quick (30 mins)

Precision

High

Features

self

Available in

Entreprise Edition, Exakat Cloud