3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); class TClass { public function __construct(String $s) {} } $test_values = ['string', null, [1], 1, 3.14, true]; foreach ($test_values as $v) { try { $t = new TClass($v); } catch (TypeError $e) { // Must be catched for null, Int, Float, Array: echo 'OK, catched: ' . $e->getMessage() . PHP_EOL; } } echo PHP_EOL . 'Now the same code with eval():' . PHP_EOL; foreach ($test_values as $v) { try { eval('declare(strict_types=1); $t = new TClass($v);'); } catch (TypeError $e) { // Must be catched for null, Int, Float, Array: echo 'OK, catched: ' . $e->getMessage() . PHP_EOL; } } // BUG: there are NO TypeError for Int, Float, Bool
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 15
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 28
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 28
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
Branch analysis from position: 15
Found catch point at position: 8
Branch analysis from position: 8
2 jumps found. (Code = 107) Position 1 = 9, Position 2 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Found catch point at position: 21
Branch analysis from position: 21
2 jumps found. (Code = 107) Position 1 = 22, Position 2 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
filename:       /in/vPgvb
function name:  (null)
number of ops:  30
compiled vars:  !0 = $test_values, !1 = $v, !2 = $t, !3 = $e
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                       !0, <array>
   10     1      > FE_RESET_R                                           $5      !0, ->15
          2    > > FE_FETCH_R                                                   $5, !1, ->15
   12     3    >   NEW                                                  $6      'TClass'
          4        SEND_VAR_EX                                                  !1
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !2, $6
          7      > JMP                                                          ->14
   13     8  E > > CATCH                                           last         'TypeError'
   15     9    >   INIT_METHOD_CALL                                             !3, 'getMessage'
         10        DO_FCALL                                          0  $9      
         11        CONCAT                                               ~10     'OK%2C+catched%3A+', $9
         12        CONCAT                                               ~11     ~10, '%0A'
         13        ECHO                                                         ~11
   10    14    > > JMP                                                          ->2
         15    >   FE_FREE                                                      $5
   20    16        ECHO                                                         '%0ANow+the+same+code+with+eval%28%29%3A%0A'
   22    17      > FE_RESET_R                                           $12     !0, ->28
         18    > > FE_FETCH_R                                                   $12, !1, ->28
   24    19    >   INCLUDE_OR_EVAL                                              'declare%28strict_types%3D1%29%3B+%24t+%3D+new+TClass%28%24v%29%3B', EVAL
         20      > JMP                                                          ->27
   25    21  E > > CATCH                                           last         'TypeError'
   27    22    >   INIT_METHOD_CALL                                             !3, 'getMessage'
         23        DO_FCALL                                          0  $14     
         24        CONCAT                                               ~15     'OK%2C+catched%3A+', $14
         25        CONCAT                                               ~16     ~15, '%0A'
         26        ECHO                                                         ~16
   22    27    > > JMP                                                          ->18
         28    >   FE_FREE                                                      $12
   31    29      > RETURN                                                       1

Class TClass:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vPgvb
function name:  __construct
number of ops:  2
compiled vars:  !0 = $s
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
          1      > RETURN                                                       null

End of function __construct

End of class TClass.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
125.25 ms | 480 KiB | 7 Q