You're overwriting $obj each iteration. Instead, do this:
$myArray = array();
foreach($array as $counts) {
array_push($myArray, new fiber());
}
Now you can access each fiber with $myArray[0] etc.
Here's a more complete and generic example (note the use of [] isn't supported before php 5.4).
class Fiber {
private $x;
public function __construct($x) {
$this->x = $x;
}
public function getX() {
return $this->x;
}
}
$x = [1,2,3];
$Fibers = [];
foreach($x as $v) {
$Fibers[]= new Fiber($v);
}
echo $Fibers[0]->getX(); //1
echo $Fibers[1]->getX(); //2
echo $Fibers[2]->getX(); //3
I really prefer $array[]= 'value' over array_push($array, 'value');
1,2,3might be a "code smell".. It's certainly not necessary in order to loop through and create objects, as you could just as soon use a for loop where$i<2or$i<$lengthetc