I have one class that creates an instance of another class. Is it possible for the second class to retrieve parameters from the calling class.
For example
Class_A {
protected $myArray = array('item 1', 'item2', 'item3')
public function __construct()
{
$nextClass = new ClassB();
echo $nextClass->countArrayItems();
}
}
Class_B {
public function countArrayItems()
{
return count(Class_A->myArray);
}
}
$newClass = new Class_A;
You could pass a reference to your
Class_Ainstance to yourClass_Bconstructor:(as noted by @chris, Class_A->myArray needs to be public)