3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class CanBeStrung { public function __toString(): string { return 'I\'m highly strung'; } } function isItStringy(string|Stringable $possibleStringType): bool { return true; } assert(isItStringy('a string') === true); assert(isItStringy(new CanBeStrung()) === true); try { assert(isItStringy(42) === false); } catch (TypeError $e) { echo '42 isnt a string' . PHP_EOL; } try { assert(isItStringy(new stdClass()) === false); } catch (TypeError $e) { echo 'stdClass cant be strung' . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 31
Branch analysis from position: 31
2 jumps found. (Code = 107) Position 1 = 32, Position 2 = -2
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Found catch point at position: 45
Branch analysis from position: 45
2 jumps found. (Code = 107) Position 1 = 46, Position 2 = -2
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DlBh4
function name:  (null)
number of ops:  48
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   DECLARE_CLASS                                            'canbestrung'
   18     1        ASSERT_CHECK                                             
          2        INIT_FCALL                                               'assert'
          3        INIT_FCALL                                               'isitstringy'
          4        SEND_VAL                                                 'a+string'
          5        DO_FCALL                                      0  $1      
          6        TYPE_CHECK                                    8  ~2      $1
          7        SEND_VAL                                                 ~2
          8        SEND_VAL                                                 'assert%28isItStringy%28%27a+string%27%29+%3D%3D%3D+true%29'
          9        DO_ICALL                                                 
   19    10        ASSERT_CHECK                                             
         11        INIT_FCALL                                               'assert'
         12        INIT_FCALL                                               'isitstringy'
         13        NEW                                              $4      'CanBeStrung'
         14        DO_FCALL                                      0          
         15        SEND_VAR                                                 $4
         16        DO_FCALL                                      0  $6      
         17        TYPE_CHECK                                    8  ~7      $6
         18        SEND_VAL                                                 ~7
         19        SEND_VAL                                                 'assert%28isItStringy%28new+CanBeStrung%28%29%29+%3D%3D%3D+true%29'
         20        DO_ICALL                                                 
   22    21        ASSERT_CHECK                                             
         22        INIT_FCALL                                               'assert'
         23        INIT_FCALL                                               'isitstringy'
         24        SEND_VAL                                                 42
         25        DO_FCALL                                      0  $9      
         26        TYPE_CHECK                                    4  ~10     $9
         27        SEND_VAL                                                 ~10
         28        SEND_VAL                                                 'assert%28isItStringy%2842%29+%3D%3D%3D+false%29'
         29        DO_ICALL                                                 
         30      > JMP                                                      ->33
   23    31  E > > CATCH                                       last         'TypeError'
   24    32    >   ECHO                                                     '42+isnt+a+string%0A'
   28    33    >   ASSERT_CHECK                                             
         34        INIT_FCALL                                               'assert'
         35        INIT_FCALL                                               'isitstringy'
         36        NEW                                              $12     'stdClass'
         37        DO_FCALL                                      0          
         38        SEND_VAR                                                 $12
         39        DO_FCALL                                      0  $14     
         40        TYPE_CHECK                                    4  ~15     $14
         41        SEND_VAL                                                 ~15
         42        SEND_VAL                                                 'assert%28isItStringy%28new+stdClass%28%29%29+%3D%3D%3D+false%29'
         43        DO_ICALL                                                 
         44      > JMP                                                      ->47
   29    45  E > > CATCH                                       last         'TypeError'
   30    46    >   ECHO                                                     'stdClass+cant+be+strung%0A'
   31    47    > > RETURN                                                   1

Function isitstringy:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DlBh4
function name:  isItStringy
number of ops:  4
compiled vars:  !0 = $possibleStringType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1      > RETURN                                                   <true>
   16     2*       VERIFY_RETURN_TYPE                                       
          3*     > RETURN                                                   null

End of function isitstringy

Class CanBeStrung:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DlBh4
function name:  __toString
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E > > RETURN                                                   'I%27m+highly+strung'
   10     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function __tostring

End of class CanBeStrung.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.69 ms | 1402 KiB | 19 Q