class A
{
private static array $instances = [];
public readonly int $value;
public function __construct(?int $value = null)
{
if ($value !== null) {
$this->value = $value;
static::$instances[] = $this;
}
}
public function summ(): int
{
return array_reduce(
static::$instances,
fn($acc, $cur) => $acc + $cur->value,
0
);
}
}
new A(2);
new A(3);
$summ = (new A())->summ();
print $summ; // 5 const p = new Promise(...).then(...).then(...).catch();можно записать какconst p1 = new Promise(...);
const p2 = p1.then(...);
const p3 = p2.then(...);
const p4 = p3.catch(...); $json = file_get_contents('php://input');
$data = json_decode($json); axios.get(url[, config])