What are the best practices for accessing variables from one class in a static method of another class in PHP?

When accessing variables from one class in a static method of another class in PHP, it is best practice to use dependency injection. This involves passing an instance of the class containing the variables as a parameter to the static method. This allows the static method to access the variables through the passed instance.

<?php

class ClassA {
    public $variable = 'Hello World';
}

class ClassB {
    public static function accessVariable(ClassA $instance) {
        echo $instance->variable;
    }
}

$instanceA = new ClassA();
ClassB::accessVariable($instanceA); // Output: Hello World

?>