echo OOP php method : <p>I had one lesson in OOP which included messaging between classes. On the tutorial, the guy just showed var_dump output version of that. I wanted to play with the code and change from var_dump to echo output, because it would me more useful in future. I just couldn't find any solution so you guys are my only option. Here's the code.</p>

<pre><code>&lt;?php

class Person {

    protected $name;

    public function __construct($name) 
    {
        $this-&gt;name = $name;
    }

    public function getName()
    {
        return $this-&gt;name;
    } 
}

class Business {

    // adding Staff class to Business
    public function __construct(Staff $staff)
    {
        $this-&gt;staff = $staff;
    }

    // manual hire(adding Person to Staff) 
    public function hire(Person $person)
    {
        // add to staff
        $this-&gt;staff-&gt;add($person);
    }

    // fetch members
    public function getStaffMembers()
    {
        return $this-&gt;staff-&gt;members();
    }
}

class Staff {

     // adding people from Person class to "member" variable
     protected $members = [];

    public function __construct($members = []) 
    {
        $this-&gt;members = $members;
    }

    // adding person to members
    public function add(Person $person) 
    {
        $this-&gt;members[] = $person;
    }

    public function members()
    {
        return $this-&gt;members;
    }
}

// you can also create an array with this method

$bros = [
    'Bro', 
    'Zdenko', 
    'Miljan', 
    'Kesten'
];

// pretty simple to understand this part

$employees = new Person([$bros]);

$staff = new Staff([$employees]);

$business = new Business($staff);

var_dump($business-&gt;getStaffMembers());
// or the print_r, it doesn't matter
print_r($business-&gt;getStaffMembers());

?&gt;
</code></pre>
