<?php interface StrategyInterface { public function run(); } class Strategy implements StrategyInterface { protected ?string $value = null; public function __construct(private Closure $closure) { $this->value = (string) rand(1, 100); } public function run() { $this->closure->call($this); } } for ($i = 0; $i < 10; $i++) { $strategy = new Strategy(function() { var_dump($this->value); }); $strategy->run(); }
You have javascript disabled. You will not be able to edit any code.