Access global variable from within a class

please don’t use the global method that is being suggested. That makes my stomach hurt.

Pass $a into the constructor of B.

class A {
    function Show(){
            echo "ciao";
    }
}

$a = new A();
$b = new B( $a );

class B {
    function __construct( $a ) {
        $a->Show();
    }
}

Leave a Comment