1.2.340. Dependency Injection

A dependency injection is a typehinted argument, that is stored in a property by the constructor.

<?php

// Classic dependency injection
class foo {
    private $bar;

    public function __construct(Bar $bar) {
        $this->bar = $bar;
    }

    public function doSomething($args) {
        return $this->bar->barbar($args);
    }
}

// Without typehint, this is not a dependency injection
class foo {
    private $bar;

    public function __construct($bar) {
        $this->bar = $bar;
    }
}

?>

See also Understanding Dependency Injection.

1.2.340.1. Specs

Short name

Patterns/DependencyInjection

Rulesets

All, Appinfo, CE, Changed Behavior

Exakat since

0.11.6

PHP Version

All

Severity

Time To Fix

Precision

Very high

Features

dependency-injection, pattern

Available in

Entreprise Edition, Community Edition, Exakat Cloud