3v4l.org

run code in 300+ PHP versions simultaneously
<?php class NumberWrapper { private $number; public function __construct($number) { $this->number = $number; } } class CollectionGenerator { public function create($array, $class) { if(!class_exists($class)) throw new Exception('Kur'); $collection = []; foreach($array as $item) { $collection[] = new $class($item); } } } $someArray = [1, 2, 3, 4]; $wrappedArray = CollectionGenerator::create($someArray, 'NumberWrapper'); var_dump($wrappedArray);

preferences:
38.01 ms | 402 KiB | 5 Q