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());
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 37
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 37
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/aYGUE
function name:  (null)
number of ops:  47
compiled vars:  !0 = $p, !1 = $r, !2 = $props, !3 = $array, !4 = $prop
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  107     0  E >   NEW                                              $5      'Parser'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $5
  108     3        NEW                                              $8      'ReflectionClass'
          4        NEW                                              $9      'Teste'
          5        DO_FCALL                                      0          
          6        SEND_VAR_NO_REF_EX                                       $9
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $8
  109     9        INIT_METHOD_CALL                                         !1, 'getProperties'
         10        DO_FCALL                                      0  $13     
         11        ASSIGN                                                   !2, $13
  110    12        ASSIGN                                                   !3, <array>
  111    13      > FE_RESET_R                                       $16     !2, ->37
         14    > > FE_FETCH_R                                               $16, !4, ->37
  112    15    >   INIT_FCALL                                               'var_dump'
         16        INIT_METHOD_CALL                                         !0, 'parse'
         17        INIT_METHOD_CALL                                         !4, 'getDocComment'
         18        DO_FCALL                                      0  $17     
         19        SEND_VAR_NO_REF_EX                                       $17
         20        DO_FCALL                                      0  $18     
         21        INIT_METHOD_CALL                                         $18, 'getParse'
         22        DO_FCALL                                      0  $19     
         23        SEND_VAR                                                 $19
         24        DO_ICALL                                                 
  113    25        INIT_METHOD_CALL                                         !4, 'getName'
         26        DO_FCALL                                      0  $21     
         27        INIT_METHOD_CALL                                         !0, 'parse'
         28        INIT_METHOD_CALL                                         !4, 'getDocComment'
         29        DO_FCALL                                      0  $23     
         30        SEND_VAR_NO_REF_EX                                       $23
         31        DO_FCALL                                      0  $24     
         32        INIT_METHOD_CALL                                         $24, 'getParse'
         33        DO_FCALL                                      0  $25     
         34        ASSIGN_DIM                                               !3, $21
         35        OP_DATA                                                  $25
  111    36      > JMP                                                      ->14
         37    >   FE_FREE                                                  $16
  115    38        ECHO                                                     '%3Cpre%3E'
  116    39        INIT_FCALL                                               'print_r'
         40        FETCH_DIM_R                                      ~26     !3, 'idade'
         41        FETCH_DIM_R                                      ~27     ~26, 'Column'
         42        INIT_METHOD_CALL                                         ~27, 'getType'
         43        DO_FCALL                                      0  $28     
         44        SEND_VAR                                                 $28
         45        DO_ICALL                                                 
         46      > RETURN                                                   1

Class Parser:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   NEW                                              $1      'ArrayObject'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'parse'
          3        OP_DATA                                                  $1
    9     4      > RETURN                                                   null

End of function __construct

Function parse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  parse
number of ops:  17
compiled vars:  !0 = $str, !1 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%2F%40%28.%2A%29+%5C%28%28.%2A%29%5C%29%2F%0A'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
   13     6        INIT_METHOD_CALL                                         'fill'
          7        CHECK_FUNC_ARG                                           
          8        FETCH_DIM_FUNC_ARG                               $3      !1, 1
          9        SEND_FUNC_ARG                                            $3
         10        CHECK_FUNC_ARG                                           
         11        FETCH_DIM_FUNC_ARG                               $4      !1, 2
         12        SEND_FUNC_ARG                                            $4
         13        DO_FCALL                                      0          
   14    14        FETCH_THIS                                       ~6      
         15      > RETURN                                                   ~6
   15    16*     > RETURN                                                   null

End of function parse

Function fill:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 6
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 6
Branch analysis from position: 23
Branch analysis from position: 6
filename:       /in/aYGUE
function name:  fill
number of ops:  26
compiled vars:  !0 = $classes, !1 = $args, !2 = $count, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        COUNT                                            ~4      !0
          3        ASSIGN                                                   !2, ~4
   19     4        ASSIGN                                                   !3, 0
          5      > JMP                                                      ->21
   20     6    >   FETCH_OBJ_R                                      ~7      'parse'
          7        INIT_METHOD_CALL                                         ~7, 'offsetSet'
          8        CHECK_FUNC_ARG                                           
          9        FETCH_DIM_FUNC_ARG                               $8      !0, !3
         10        SEND_FUNC_ARG                                            $8
         11        FETCH_DIM_R                                      ~9      !0, !3
         12        FETCH_CLASS                                   0  $10     ~9
         13        NEW                                              $11     $10
         14        CHECK_FUNC_ARG                                           
         15        FETCH_DIM_FUNC_ARG                               $12     !1, !3
         16        SEND_FUNC_ARG                                            $12
         17        DO_FCALL                                      0          
         18        SEND_VAR_NO_REF_EX                                       $11
         19        DO_FCALL                                      0          
   19    20        PRE_INC                                                  !3
         21    >   IS_SMALLER                                               !3, !2
         22      > JMPNZ                                                    ~16, ->6
   22    23    >   FETCH_THIS                                       ~17     
         24      > RETURN                                                   ~17
   23    25*     > RETURN                                                   null

End of function fill

Function getparse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  getParse
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   FETCH_OBJ_R                                      ~0      'parse'
          1      > RETURN                                                   ~0
   27     2*     > RETURN                                                   null

End of function getparse

Function getdata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  getData
number of ops:  15
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        FETCH_OBJ_R                                      ~1      'parse'
          2        INIT_METHOD_CALL                                         ~1, 'offsetExists'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > JMPZ                                                     $2, ->12
          6    >   FETCH_OBJ_R                                      ~3      'parse'
          7        INIT_METHOD_CALL                                         ~3, 'offsetGet'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $4      
         10        QM_ASSIGN                                        ~5      $4
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~5      null
         13    > > RETURN                                                   ~5
   31    14*     > RETURN                                                   null

End of function getdata

End of class Parser.

Class Column:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  __construct
number of ops:  21
compiled vars:  !0 = $args, !1 = $parse
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
   41     5        INIT_METHOD_CALL                                         'setLength'
          6        CHECK_FUNC_ARG                                           
          7        FETCH_OBJ_FUNC_ARG                               $4      !1, 'length'
          8        SEND_FUNC_ARG                                            $4
          9        DO_FCALL                                      0          
   42    10        INIT_METHOD_CALL                                         'setName'
         11        CHECK_FUNC_ARG                                           
         12        FETCH_OBJ_FUNC_ARG                               $6      !1, 'name'
         13        SEND_FUNC_ARG                                            $6
         14        DO_FCALL                                      0          
   43    15        INIT_METHOD_CALL                                         'setType'
         16        CHECK_FUNC_ARG                                           
         17        FETCH_OBJ_FUNC_ARG                               $8      !1, 'type'
         18        SEND_FUNC_ARG                                            $8
         19        DO_FCALL                                      0          
   44    20      > RETURN                                                   null

End of function __construct

Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  getName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1      > RETURN                                                   ~0
   48     2*     > RETURN                                                   null

End of function getname

Function gettype:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  getType
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   FETCH_OBJ_R                                      ~0      'type'
          1      > RETURN                                                   ~0
   52     2*     > RETURN                                                   null

End of function gettype

Function getlength:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  getLength
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~0      'length'
          1      > RETURN                                                   ~0
   56     2*     > RETURN                                                   null

End of function getlength

Function setname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  setName
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
   59     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   60     3      > RETURN                                                   null

End of function setname

Function settype:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  setType
number of ops:  4
compiled vars:  !0 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   63     1        ASSIGN_OBJ                                               'type'
          2        OP_DATA                                                  !0
   64     3      > RETURN                                                   null

End of function settype

Function setlength:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  setLength
number of ops:  4
compiled vars:  !0 = $length
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
   67     1        ASSIGN_OBJ                                               'length'
          2        OP_DATA                                                  !0
   68     3      > RETURN                                                   null

End of function setlength

End of class Column.

Class Form:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  __construct
number of ops:  11
compiled vars:  !0 = $args, !1 = $parser
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
   77     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
   78     5        INIT_METHOD_CALL                                         'setField'
          6        CHECK_FUNC_ARG                                           
          7        FETCH_OBJ_FUNC_ARG                               $4      !1, 'field'
          8        SEND_FUNC_ARG                                            $4
          9        DO_FCALL                                      0          
   79    10      > RETURN                                                   null

End of function __construct

Function getfield:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  getField
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   FETCH_OBJ_R                                      ~0      'field'
          1      > RETURN                                                   ~0
   83     2*     > RETURN                                                   null

End of function getfield

Function setfield:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aYGUE
function name:  setField
number of ops:  4
compiled vars:  !0 = $field
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   RECV                                             !0      
   86     1        ASSIGN_OBJ                                               'field'
          2        OP_DATA                                                  !0
   87     3      > RETURN                                                   null

End of function setfield

End of class Form.

Class Teste: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.33 ms | 1416 KiB | 21 Q