1.2.1139. Static Call May Be Truly Static

Static calls are allowed on objects. Although, when using typehinting, it is better to use the actual type, and allow PHP to prepare this at compilation time, not at execution time.

When the typehint is an interface or an abstract class, then the object may hold a different type : those cases are omitted. This is a micro-optimisation. The call is very fast, but will gain another 1/3 with a static syntax.

<?php

function foo(A $a, $b) {
    // This could use \A instead of $a
    echo $a::class;

    // This will be arbitrary and needs $b
    echo $a::class;
}

?>

1.2.1139.1. Suggestions

  • Use the actual typehint of the parameter or property

  • Use a parent of the typehint of the parameter or property

1.2.1139.2. Specs

Short name

Performances/StaticCallDontNeedObjects

Rulesets

All, Performances

Exakat since

2.3.6

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

static

Available in

Entreprise Edition, Exakat Cloud