What are some alternative approaches to achieving the desired functionality without using static properties in PHP classes?

Using static properties in PHP classes can lead to tight coupling and make the code harder to test and maintain. To achieve the desired functionality without static properties, you can use dependency injection to pass the necessary values to the class instance when it is created. This approach promotes better encapsulation and allows for easier testing and flexibility in the codebase.

<?php

class MyClass {
    private $dependency;

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

    public function doSomething() {
        // Use $this->dependency here
    }
}

$dependency = new Dependency();
$myClass = new MyClass($dependency);
$myClass->doSomething();