- array_map: documentation ( source)
<?php
abstract class Foo {
abstract protected static function things();
protected $t;
protected function __construct($t) {
$this->t = $t;
}
public function getT() {
return $this->t;
}
public static function all() {
return array_map(function($t) { return new static($t); }, static::things());
}
}
class Bar extends Foo {
protected static function things() {
return [10, 20, 30];
}
}
$bars = Bar::all();
foreach ($bars as $bar) {
echo $bar->getT()."\n";
}