3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Parser { private $parse; public function __construct() { $this->parse = new ArrayObject(); } public function parse($str){ preg_match_all("/@(.*) \((.*)\)/\n", $str, $matches); $this->fill($matches[1],$matches[2]); return $this; } protected function fill(array $classes, array $args){ $count = count($classes); for($i=0;$i<$count;$i++){ $this->parse->offsetSet($classes[$i], new $classes[$i]($args[$i])); } return $this; } function getParse() { return $this->parse; } public function getData($name) { return $this->parse->offsetExists($name)?$this->parse->offsetGet($name):NULL; } } class Column { private $name; private $type; private $length; function __construct($args) { $parse = json_decode($args); $this->setLength($parse->length); $this->setName($parse->name); $this->setType($parse->type); } function getName() { return $this->name; } function getType() { return $this->type; } function getLength() { return $this->length; } function setName($name) { $this->name = $name; } function setType($type) { $this->type = $type; } function setLength($length) { $this->length = $length; } } class Form { private $field; function __construct($args) { $parser = json_decode($args); $this->setField($parser->field); } function getField() { return $this->field; } function setField($field) { $this->field = $field; } } class Teste { /** * @Column ({"name":"name","type":"varchar","length":123}) * @Form ({"field":"nome"}) */ private $nome; /** * @Column ({"name":"idade","type":"int","length":123}) * @Form ({"field":"idade"}) */ private $idade; } $p = new Parser(); $r = new ReflectionClass(new Teste()); $props = $r->getProperties(); $array = array(); foreach($props as $prop){ var_dump($p->parse($prop->getDocComment())->getParse()); $array[$prop->getName()] = $p->parse($prop->getDocComment())->getParse(); } echo '<pre>'; print_r($array['idade']['Column']->getType());

preferences:
43.56 ms | 402 KiB | 5 Q