I have grouped a few functions together in a class. Some of the functions will be using the same list to do some computational work. Is there a way to put the list so that all the functions can still access the list instead of putting the list inside each functions that needs the list?
// Simplified version of what I am trying to do
Class TestGroup
{
public $classArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
public function getFirstFiveElemFromArray()
{
$firstFive = array_slice($this -> $classArray, 0, 5, true);
return $firstFive;
}
public function sumFirstEightElemFromArray()
{
//methods to get first eight elements and sum them up
}
}
$test = new TestGroup;
echo $test -> getFirstFiveElemFromArray();
This is the error message I am getting:
Undefined variable: classArray in C:\wamp\www\..