3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class AbstractModel { const TYPE_STRING = 'string'; const TYPE_INT = 'int'; const TYPE_FLOAT = 'float'; const TYPE_BOOL = 'bool'; const TYPE_ARRAY = 'array'; const TYPE_DATE_TIME = 'date-time'; const TYPE_MODEL = 'model'; const TYPE_MODEL_ARRAY = 'model-array'; /** * Returns an array of key value pairs representing the properties exposed * by the model and their types * * @return array */ abstract public function getModelProperties(); /** * Get a list of properties that can store a null value * * @return array */ public function getNullableProperties() { return []; } private function functionToProperty($name, $type) { if (strrpos($name, $type) === 0) { $property = lcfirst(substr($name, strlen($type))); $modelProperties = $this->getModelProperties(); if (!isset($modelProperties[$property])) { throw new \Exception('Property not registered: ' . $property); } return $property; } return false; } /** * Serialize value into snapshot format * * @param mixed $value Value to serialize * @param string $type Type of value * * @return mixed */ protected static function snapshotSerialize($value, $type) { switch ($type) { case self::TYPE_STRING: if (null !== $value) { return (string) $value; } break; case self::TYPE_INT: if (null !== $value) { return (int) $value; } break; case self::TYPE_FLOAT: if (null !== $value) { return (float) $value; } break; case self::TYPE_BOOL: if (null !== $value) { return (bool) $value; } break; case self::TYPE_DATE_TIME: if ($value instanceof \DateTime) { return [ 'text' => $value->format('Y-m-d H:i:s'), 'zone' => $value->getTimezone()->getName() ]; } return null; case self::TYPE_MODEL: $snapshot = $value->toSnapshot(); $snapshot['_class'] = get_class($value); return $snapshot; case self::TYPE_MODEL_ARRAY: return array_map(function (AbstractModel $item) { return self::snapshotSerialize($item, self::TYPE_MODEL); }, $value); } return $value; } /** * Unserialize from snapshot format * * @param mixed $value Value to unserialize * @param string $type Type of value * * @return mixed */ protected static function snapshotUnserialize($value, $type) { if (null === $value) { return null; } switch ($type) { case self::TYPE_DATE_TIME: if (!is_array($value) || !isset($value['text'], $value['zone'])) { throw new \Exception('Invalid date time type in snapshot'); } return new \DateTime($value['text'], new \DateTimeZone($value['zone'])); case self::TYPE_MODEL: if (!isset($value['_class'])) { throw new \Exception('Invalid model type in snapshot'); } $class = $value['_class']; unset($value['_class']); return $class::fromSnapshot($value); case self::TYPE_MODEL_ARRAY: if (!is_array($value)) { throw new \Exception('Invalid model array type in snapshot'); } return array_map(function (array $item) { return self::snapshotUnserialize($item, self::TYPE_MODEL); }, $value); } return $value; } protected static function cast($value, $type) { switch ($type) { case self::TYPE_STRING: return (string) $value; case self::TYPE_INT: return (int) $value; case self::TYPE_FLOAT: return (float) $value; case self::TYPE_BOOL: return (bool) $value; case self::TYPE_ARRAY: return (array) $value; case self::TYPE_DATE_TIME: if (!$value instanceof \DateTime) { throw new \InvalidArgumentException('Expected instance of DateTime for date time type'); } return $value; case self::TYPE_MODEL: if (!$value instanceof AbstractModel) { throw \InvalidArgumentException('Instance of AbstractModel expected for model type'); } return $value; case self::TYPE_MODEL_ARRAY: if (!is_array($value)) { throw \InvalidArgumentException('Array expected for model array type'); } return array_map(function (AbstractModel $item) { return self::cast($item, self::TYPE_MODEL); }, $value); } throw new \Exception('Unknown type: ' . $type); } /** * Applies a property map to the object * * @param array $map A property map * * @return $this * * @throws \Exception If given unregistered property */ public function applyMap($map) { $modelProperties = $this->getModelProperties(); foreach ($map as $property => $value) { if (!isset($modelProperties[$property])) { continue; // throw new \Exception('Property not registered: ' . $property); } $type = $modelProperties[$property]; if (self::TYPE_STRING !== $type && is_string($value) && strlen($value) === 0) { $value = null; } if (null === $value && in_array($property, $this->getNullableProperties())) { $this->$property = null; } else { $this->$property = self::snapshotUnserialize($value, $type); } } return $this; } /** * Instantiates a model class from a snapshot * * @param array $snapshot The snapshot * * @return AbstractModel */ public static function fromSnapshot($snapshot) { $class = get_called_class(); $object = new $class; $object->applyMap($snapshot); return $object; } /** * Creates a snapshot of the model class * * @return array */ public function toSnapshot() { $modelProperties = $this->getModelProperties(); $snapshot = array(); foreach ($modelProperties as $property => $type) { $snapshot[$property] = self::snapshotSerialize($this->$property, $type); } return $snapshot; } public function __call($name, $arguments) { $modelProperties = $this->getModelProperties(); if(false !== ($property = $this->functionToProperty($name, 'is'))) { if (self::TYPE_BOOL !== $modelProperties[$property] ) { throw new \Exception('Can only use isser on boolean property'); } return $this->$property; } elseif (false !== ($property = $this->functionToProperty($name, 'set'))) { if (1 !== count($arguments)) { throw new \Exception('Setter must be called with one argument only'); } if (null === $arguments[0] && in_array($property, $this->getNullableProperties())) { $this->$property = null; } else { $this->$property = self::cast($arguments[0], $modelProperties[$property]); } return $this; } elseif (false !== ($property = $this->functionToProperty($name, 'get'))) { if (null === $this->$property && in_array($property, $this->getNullableProperties())) { return null; } else { return $this->$property; } } trigger_error('Call to undefined method ' . get_called_class() . ':' . $name); } } class A extends AbstractModel { private $bool; public function getModelProperties() { return ['bool' => self::TYPE_BOOL]; } } $a = A::fromSnapshot(['bool' => 'true']); var_dump($a); var_dump($a->getBool());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EpTDM
function name:  (null)
number of ops:  13
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  310     0  E >   INIT_STATIC_METHOD_CALL                                  'A', 'fromSnapshot'
          1        SEND_VAL                                                 <array>
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
  311     4        INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
  312     7        INIT_FCALL                                               'var_dump'
          8        INIT_METHOD_CALL                                         !0, 'getBool'
          9        DO_FCALL                                      0  $4      
         10        SEND_VAR                                                 $4
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FEpTDM%3A99%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EpTDM
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   99     0  E >   RECV                                             !0      
  100     1        INIT_STATIC_METHOD_CALL                                  'snapshotSerialize'
          2        SEND_VAR_EX                                              !0
          3        FETCH_CLASS_CONSTANT                             ~1      'TYPE_MODEL'
          4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
  101     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FEpTDM%3A99%240

Function %00%7Bclosure%7D%2Fin%2FEpTDM%3A144%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EpTDM
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  144     0  E >   RECV                                             !0      
  145     1        INIT_STATIC_METHOD_CALL                                  'snapshotUnserialize'
          2        SEND_VAR_EX                                              !0
          3        FETCH_CLASS_CONSTANT                             ~1      'TYPE_MODEL'
          4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
  146     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FEpTDM%3A144%241

Function %00%7Bclosure%7D%2Fin%2FEpTDM%3A189%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EpTDM
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  189     0  E >   RECV                                             !0      
  190     1        INIT_STATIC_METHOD_CALL                                  'cast'
          2        SEND_VAR_EX                                              !0
          3        FETCH_CLASS_CONSTANT                             ~1      'TYPE_MODEL'
          4        SEND_VAL_EX                                              ~1
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
  191     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FEpTDM%3A189%242

Class AbstractModel:
Function getmodelproperties:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EpTDM
function name:  getModelProperties
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E > > RETURN                                                   null

End of function getmodelproperties

Function getnullableproperties:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EpTDM
function name:  getNullableProperties
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E > > RETURN                                                   <array>
   30     1*     > RETURN                                                   null

End of function getnullableproperties

Function functiontoproperty:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 29
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EpTDM
function name:  functionToProperty
number of ops:  31
compiled vars:  !0 = $name, !1 = $type, !2 = $property, !3 = $modelProperties
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   34     2        INIT_FCALL                                               'strrpos'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $4      
          6        IS_IDENTICAL                                             $4, 0
          7      > JMPZ                                                     ~5, ->29
   35     8    >   INIT_FCALL                                               'lcfirst'
          9        INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        STRLEN                                           ~6      !1
         12        SEND_VAL                                                 ~6
         13        DO_ICALL                                         $7      
         14        SEND_VAR                                                 $7
         15        DO_ICALL                                         $8      
         16        ASSIGN                                                   !2, $8
   37    17        INIT_METHOD_CALL                                         'getModelProperties'
         18        DO_FCALL                                      0  $10     
         19        ASSIGN                                                   !3, $10
   39    20        ISSET_ISEMPTY_DIM_OBJ                         0  ~12     !3, !2
         21        BOOL_NOT                                         ~13     ~12
         22      > JMPZ                                                     ~13, ->28
   40    23    >   NEW                                              $14     'Exception'
         24        CONCAT                                           ~15     'Property+not+registered%3A+', !2
         25        SEND_VAL_EX                                              ~15
         26        DO_FCALL                                      0          
         27      > THROW                                         0          $14
   43    28    > > RETURN                                                   !2
   46    29    > > RETURN                                                   <false>
   47    30*     > RETURN                                                   null

End of function functiontoproperty

Function snapshotserialize:
Finding entry points
Branch analysis from position: 0
9 jumps found. (Code = 188) Position 1 = 18, Position 2 = 23, Position 3 = 28, Position 4 = 33, Position 5 = 38, Position 6 = 51, Position 7 = 58, Position 8 = 64, Position 9 = 3
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 50
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 23
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 28
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 33
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 38
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 51
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 58
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
Branch analysis from position: 58
Branch analysis from position: 51
Branch analysis from position: 38
Branch analysis from position: 33
Branch analysis from position: 28
Branch analysis from position: 23
Branch analysis from position: 18
filename:       /in/EpTDM
function name:  snapshotSerialize
number of ops:  66
compiled vars:  !0 = $value, !1 = $type, !2 = $snapshot
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   59     2      > SWITCH_STRING                                            !1, [ 'string':->18, 'int':->23, 'float':->28, 'bool':->33, 'date-time':->38, 'model':->51, 'model-array':->58, ], ->64
          3    >   IS_EQUAL                                                 !1, 'string'
          4      > JMPNZ                                                    ~3, ->18
          5    >   IS_EQUAL                                                 !1, 'int'
          6      > JMPNZ                                                    ~3, ->23
          7    >   IS_EQUAL                                                 !1, 'float'
          8      > JMPNZ                                                    ~3, ->28
          9    >   IS_EQUAL                                                 !1, 'bool'
         10      > JMPNZ                                                    ~3, ->33
         11    >   IS_EQUAL                                                 !1, 'date-time'
         12      > JMPNZ                                                    ~3, ->38
         13    >   IS_EQUAL                                                 !1, 'model'
         14      > JMPNZ                                                    ~3, ->51
         15    >   IS_EQUAL                                                 !1, 'model-array'
         16      > JMPNZ                                                    ~3, ->58
         17    > > JMP                                                      ->64
   61    18    >   TYPE_CHECK                                  1020          !0
         19      > JMPZ                                                     ~4, ->22
   62    20    >   CAST                                          6  ~5      !0
         21      > RETURN                                                   ~5
   64    22    > > JMP                                                      ->64
   67    23    >   TYPE_CHECK                                  1020          !0
         24      > JMPZ                                                     ~6, ->27
   68    25    >   CAST                                          4  ~7      !0
         26      > RETURN                                                   ~7
   70    27    > > JMP                                                      ->64
   73    28    >   TYPE_CHECK                                  1020          !0
         29      > JMPZ                                                     ~8, ->32
   74    30    >   CAST                                          5  ~9      !0
         31      > RETURN                                                   ~9
   76    32    > > JMP                                                      ->64
   79    33    >   TYPE_CHECK                                  1020          !0
         34      > JMPZ                                                     ~10, ->37
   80    35    >   BOOL                                             ~11     !0
         36      > RETURN                                                   ~11
   82    37    > > JMP                                                      ->64
   85    38    >   INSTANCEOF                                               !0, 'DateTime'
         39      > JMPZ                                                     ~12, ->50
   87    40    >   INIT_METHOD_CALL                                         !0, 'format'
         41        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         42        DO_FCALL                                      0  $13     
         43        INIT_ARRAY                                       ~14     $13, 'text'
   88    44        INIT_METHOD_CALL                                         !0, 'getTimezone'
         45        DO_FCALL                                      0  $15     
         46        INIT_METHOD_CALL                                         $15, 'getName'
         47        DO_FCALL                                      0  $16     
         48        ADD_ARRAY_ELEMENT                                ~14     $16, 'zone'
         49      > RETURN                                                   ~14
   91    50    > > RETURN                                                   null
   94    51    >   INIT_METHOD_CALL                                         !0, 'toSnapshot'
         52        DO_FCALL                                      0  $17     
         53        ASSIGN                                                   !2, $17
   95    54        GET_CLASS                                        ~20     !0
         55        ASSIGN_DIM                                               !2, '_class'
         56        OP_DATA                                                  ~20
   96    57      > RETURN                                                   !2
   99    58    >   INIT_FCALL                                               'array_map'
         59        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FEpTDM%3A99%240'
  101    60        SEND_VAL                                                 ~21
         61        SEND_VAR                                                 !0
         62        DO_ICALL                                         $22     
         63      > RETURN                                                   $22
  104    64    > > RETURN                                                   !0
  105    65*     > RETURN                                                   null

End of function snapshotserialize

Function snapshotunserialize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
5 jumps found. (Code = 188) Position 1 = 13, Position 2 = 39, Position 3 = 54, Position 4 = 67, Position 5 = 6
Branch analysis from position: 13
2 jumps found. (Code = 47) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 22
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 46
Branch analysis from position: 42
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 61
Branch analysis from position: 57
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 39
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 54
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
Branch analysis from position: 54
Branch analysis from position: 39
Branch analysis from position: 13
filename:       /in/EpTDM
function name:  snapshotUnserialize
number of ops:  69
compiled vars:  !0 = $value, !1 = $type, !2 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  115     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  117     2        TYPE_CHECK                                    2          !0
          3      > JMPZ                                                     ~3, ->5
  118     4    > > RETURN                                                   null
  121     5    > > SWITCH_STRING                                            !1, [ 'date-time':->13, 'model':->39, 'model-array':->54, ], ->67
          6    >   IS_EQUAL                                                 !1, 'date-time'
          7      > JMPNZ                                                    ~4, ->13
          8    >   IS_EQUAL                                                 !1, 'model'
          9      > JMPNZ                                                    ~4, ->39
         10    >   IS_EQUAL                                                 !1, 'model-array'
         11      > JMPNZ                                                    ~4, ->54
         12    > > JMP                                                      ->67
  123    13    >   TYPE_CHECK                                  128  ~5      !0
         14        BOOL_NOT                                         ~6      ~5
         15      > JMPNZ_EX                                         ~6      ~6, ->22
         16    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~7      !0, 'text'
         17      > JMPZ_EX                                          ~7      ~7, ->20
         18    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !0, 'zone'
         19        BOOL                                             ~7      ~8
         20    >   BOOL_NOT                                         ~9      ~7
         21        BOOL                                             ~6      ~9
         22    > > JMPZ                                                     ~6, ->27
  124    23    >   NEW                                              $10     'Exception'
         24        SEND_VAL_EX                                              'Invalid+date+time+type+in+snapshot'
         25        DO_FCALL                                      0          
         26      > THROW                                         0          $10
  127    27    >   NEW                                              $12     'DateTime'
         28        CHECK_FUNC_ARG                                           
         29        FETCH_DIM_FUNC_ARG                               $13     !0, 'text'
         30        SEND_FUNC_ARG                                            $13
         31        NEW                                              $14     'DateTimeZone'
         32        CHECK_FUNC_ARG                                           
         33        FETCH_DIM_FUNC_ARG                               $15     !0, 'zone'
         34        SEND_FUNC_ARG                                            $15
         35        DO_FCALL                                      0          
         36        SEND_VAR_NO_REF_EX                                       $14
         37        DO_FCALL                                      0          
         38      > RETURN                                                   $12
  130    39    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !0, '_class'
         40        BOOL_NOT                                         ~19     ~18
         41      > JMPZ                                                     ~19, ->46
  131    42    >   NEW                                              $20     'Exception'
         43        SEND_VAL_EX                                              'Invalid+model+type+in+snapshot'
         44        DO_FCALL                                      0          
         45      > THROW                                         0          $20
  134    46    >   FETCH_DIM_R                                      ~22     !0, '_class'
         47        ASSIGN                                                   !2, ~22
  135    48        UNSET_DIM                                                !0, '_class'
  137    49        FETCH_CLASS                                   0  $24     !2
         50        INIT_STATIC_METHOD_CALL                                  $24, 'fromSnapshot'
         51        SEND_VAR_EX                                              !0
         52        DO_FCALL                                      0  $25     
         53      > RETURN                                                   $25
  140    54    >   TYPE_CHECK                                  128  ~26     !0
         55        BOOL_NOT                                         ~27     ~26
         56      > JMPZ                                                     ~27, ->61
  141    57    >   NEW                                              $28     'Exception'
         58        SEND_VAL_EX                                              'Invalid+model+array+type+in+snapshot'
         59        DO_FCALL                                      0          
         60      > THROW                                         0          $28
  144    61    >   INIT_FCALL                                               'array_map'
         62        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FEpTDM%3A144%241'
  146    63        SEND_VAL                                                 ~30
         64        SEND_VAR                                                 !0
         65        DO_ICALL                                         $31     
         66      > RETURN                                                   $31
  149    67    > > RETURN                                                   !0
  150    68*     > RETURN                                                   null

End of function snapshotunserialize

Function cast:
Finding entry points
Branch analysis from position: 0
10 jumps found. (Code = 188) Position 1 = 20, Position 2 = 22, Position 3 = 24, Position 4 = 26, Position 5 = 28, Position 6 = 30, Position 7 = 38, Position 8 = 46, Position 9 = 59, Position 10 = 3
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 53
Branch analysis from position: 49
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 24
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 26
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 28
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 30
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 38
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 46
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
Branch analysis from position: 46
Branch analysis from position: 38
Branch analysis from position: 30
Branch analysis from position: 28
Branch analysis from position: 26
Branch analysis from position: 24
Branch analysis from position: 22
Branch analysis from position: 20
filename:       /in/EpTDM
function name:  cast
number of ops:  65
compiled vars:  !0 = $value, !1 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  152     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  154     2      > SWITCH_STRING                                            !1, [ 'string':->20, 'int':->22, 'float':->24, 'bool':->26, 'array':->28, 'date-time':->30, 'model':->38, 'model-array':->46, ], ->59
          3    >   IS_EQUAL                                                 !1, 'string'
          4      > JMPNZ                                                    ~2, ->20
          5    >   IS_EQUAL                                                 !1, 'int'
          6      > JMPNZ                                                    ~2, ->22
          7    >   IS_EQUAL                                                 !1, 'float'
          8      > JMPNZ                                                    ~2, ->24
          9    >   IS_EQUAL                                                 !1, 'bool'
         10      > JMPNZ                                                    ~2, ->26
         11    >   IS_EQUAL                                                 !1, 'array'
         12      > JMPNZ                                                    ~2, ->28
         13    >   IS_EQUAL                                                 !1, 'date-time'
         14      > JMPNZ                                                    ~2, ->30
         15    >   IS_EQUAL                                                 !1, 'model'
         16      > JMPNZ                                                    ~2, ->38
         17    >   IS_EQUAL                                                 !1, 'model-array'
         18      > JMPNZ                                                    ~2, ->46
         19    > > JMP                                                      ->59
  156    20    >   CAST                                          6  ~3      !0
         21      > RETURN                                                   ~3
  159    22    >   CAST                                          4  ~4      !0
         23      > RETURN                                                   ~4
  162    24    >   CAST                                          5  ~5      !0
         25      > RETURN                                                   ~5
  165    26    >   BOOL                                             ~6      !0
         27      > RETURN                                                   ~6
  168    28    >   CAST                                          7  ~7      !0
         29      > RETURN                                                   ~7
  171    30    >   INSTANCEOF                                       ~8      !0, 'DateTime'
         31        BOOL_NOT                                         ~9      ~8
         32      > JMPZ                                                     ~9, ->37
  172    33    >   NEW                                              $10     'InvalidArgumentException'
         34        SEND_VAL_EX                                              'Expected+instance+of+DateTime+for+date+time+type'
         35        DO_FCALL                                      0          
         36      > THROW                                         0          $10
  175    37    > > RETURN                                                   !0
  178    38    >   INSTANCEOF                                       ~12     !0, 'AbstractModel'
         39        BOOL_NOT                                         ~13     ~12
         40      > JMPZ                                                     ~13, ->45

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.69 ms | 1428 KiB | 23 Q