class Apple
{
}
class Orange
{
}
new Apple()
new Apple()
new Apple()
new Apple()
$length = 10;
array_map(fn() => new Apple(), array_fill(0, $length, NULL));
function makeMany(string $className, int $quantity)
{
return array_map(fn() => new $className(), array_fill(0, $quantity, NULL));
}
// использование
makeMany("Apple", 10);
makeMany("Orange", 20);
// или
makeMany(Apple::class, 10);
makeMany(Orange::class, 20);