3v4l.org

run code in 300+ PHP versions simultaneously
<?php $config = [ "testA" => true, "testB" => 22, 0 => 0 ]; class Processor { public $systemVarA; public $systemVarB; private function validators() { return [ 'testA' => function($value) { if (!is_bool($value)) throw new \Exception( "Configuration '$name' must be boolean."); $this->systemVarA = $value; }, 'testB' => function($value) { if (!is_int($value)) throw new \Exception( "Configuration '$name' must be integer."); $this->systemVarB = $value; } ]; } public function validate($array) { $validators = $this->validators(); foreach($array as $key => $value) if(is_callable($validators[$key])) $validators[$key]($value); } } $proc = new Processor; $proc->validate($config); var_dump($proc);

preferences:
36.26 ms | 405 KiB | 5 Q