<?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);
You have javascript disabled. You will not be able to edit any code.