3v4l.org

run code in 300+ PHP versions simultaneously
<?php readonly class FormattedString { private string $value; private function __construct (string $str) { $this->value = $str; } public static function create (string $str): self|NotValidFormattedString { $matches = null; preg_match("/[a-z]{2}-[a-z]{2}-[a-z]{8}-[a-z]{1}/", $str, $matches); if (count($matches) === 0) { return new NotValidFormattedString($str, "poshel nahoi suka, chto za govno ti mne peredal, blyad"); } return new self($str); } } readonly class NotValidFormattedString { public function __construct (public string $str, public string $err) {} } class ValidateFormattedString { public function __invoke(string $str): FormattedString|NotValidFormattedString { return FormattedString::create($str); } } class SuperYellowCircle { public function __construct (public FormattedString $toChtoVMoemPrimereByloClassomYoba) {} } $stringOne = (new ValidateFormattedString)("aa-bb-cccccccc-d"); $circleOne = new SuperYellowCircle($stringOne); var_dump($circleOne); $stringTwo = (new ValidateFormattedString)("butthurt"); $circleTwo = new SuperYellowCircle($stringTwo); var_dump($circleTwo);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pJbBI
function name:  (null)
number of ops:  27
compiled vars:  !0 = $stringOne, !1 = $circleOne, !2 = $stringTwo, !3 = $circleTwo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   NEW                                              $4      'ValidateFormattedString'
          1        DO_FCALL                                      0          
          2        INIT_DYNAMIC_CALL                                        $4
          3        SEND_VAL_EX                                              'aa-bb-cccccccc-d'
          4        DO_FCALL                                      0  $6      
          5        ASSIGN                                                   !0, $6
   36     6        NEW                                              $8      'SuperYellowCircle'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $8
   37    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
   39    13        NEW                                              $12     'ValidateFormattedString'
         14        DO_FCALL                                      0          
         15        INIT_DYNAMIC_CALL                                        $12
         16        SEND_VAL_EX                                              'butthurt'
         17        DO_FCALL                                      0  $14     
         18        ASSIGN                                                   !2, $14
   40    19        NEW                                              $16     'SuperYellowCircle'
         20        SEND_VAR_EX                                              !2
         21        DO_FCALL                                      0          
         22        ASSIGN                                                   !3, $16
   41    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Class FormattedString:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pJbBI
function name:  __construct
number of ops:  4
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        ASSIGN_OBJ                                               'value'
          2        OP_DATA                                                  !0
    8     3      > RETURN                                                   null

End of function __construct

Function create:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pJbBI
function name:  create
number of ops:  23
compiled vars:  !0 = $str, !1 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        ASSIGN                                                   !1, null
   12     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAL                                                 '%2F%5Ba-z%5D%7B2%7D-%5Ba-z%5D%7B2%7D-%5Ba-z%5D%7B8%7D-%5Ba-z%5D%7B1%7D%2F'
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !1
          6        DO_ICALL                                                 
   13     7        COUNT                                            ~4      !1
          8        IS_IDENTICAL                                             ~4, 0
          9      > JMPZ                                                     ~5, ->16
   14    10    >   NEW                                              $6      'NotValidFormattedString'
         11        SEND_VAR_EX                                              !0
         12        SEND_VAL_EX                                              'poshel+nahoi+suka%2C+chto+za+govno+ti+mne+peredal%2C+blyad'
         13        DO_FCALL                                      0          
         14        VERIFY_RETURN_TYPE                                       $6
         15      > RETURN                                                   $6
   17    16    >   NEW                          self                $8      
         17        SEND_VAR_EX                                              !0
         18        DO_FCALL                                      0          
         19        VERIFY_RETURN_TYPE                                       $8
         20      > RETURN                                                   $8
   18    21*       VERIFY_RETURN_TYPE                                       
         22*     > RETURN                                                   null

End of function create

End of class FormattedString.

Class NotValidFormattedString:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pJbBI
function name:  __construct
number of ops:  7
compiled vars:  !0 = $str, !1 = $err
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        ASSIGN_OBJ                                               'str'
          3        OP_DATA                                                  !0
          4        ASSIGN_OBJ                                               'err'
          5        OP_DATA                                                  !1
          6      > RETURN                                                   null

End of function __construct

End of class NotValidFormattedString.

Class ValidateFormattedString:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pJbBI
function name:  __invoke
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        INIT_STATIC_METHOD_CALL                                  'FormattedString', 'create'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   28     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function __invoke

End of class ValidateFormattedString.

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

End of function __construct

End of class SuperYellowCircle.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.44 ms | 1008 KiB | 15 Q