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($possibleStringType): bool { if (is_string($possibleStringType)) { return true; } if(is_callable([$possibleStringType, '__toString'])) { return true; } return false; } assert(isItStringy('a string') === true); assert(isItStringy(new CanBeStrung()) === true); assert(isItStringy(42) === false); assert(isItStringy(new stdClass()) === false);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RRKkp
function name:  (null)
number of ops:  42
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   DECLARE_CLASS                                            'canbestrung'
   26     1        ASSERT_CHECK                                             
          2        INIT_FCALL                                               'assert'
          3        INIT_FCALL                                               'isitstringy'
          4        SEND_VAL                                                 'a+string'
          5        DO_FCALL                                      0  $0      
          6        TYPE_CHECK                                    8  ~1      $0
          7        SEND_VAL                                                 ~1
          8        SEND_VAL                                                 'assert%28isItStringy%28%27a+string%27%29+%3D%3D%3D+true%29'
          9        DO_ICALL                                                 
   27    10        ASSERT_CHECK                                             
         11        INIT_FCALL                                               'assert'
         12        INIT_FCALL                                               'isitstringy'
         13        NEW                                              $3      'CanBeStrung'
         14        DO_FCALL                                      0          
         15        SEND_VAR                                                 $3
         16        DO_FCALL                                      0  $5      
         17        TYPE_CHECK                                    8  ~6      $5
         18        SEND_VAL                                                 ~6
         19        SEND_VAL                                                 'assert%28isItStringy%28new+CanBeStrung%28%29%29+%3D%3D%3D+true%29'
         20        DO_ICALL                                                 
   28    21        ASSERT_CHECK                                             
         22        INIT_FCALL                                               'assert'
         23        INIT_FCALL                                               'isitstringy'
         24        SEND_VAL                                                 42
         25        DO_FCALL                                      0  $8      
         26        TYPE_CHECK                                    4  ~9      $8
         27        SEND_VAL                                                 ~9
         28        SEND_VAL                                                 'assert%28isItStringy%2842%29+%3D%3D%3D+false%29'
         29        DO_ICALL                                                 
   29    30        ASSERT_CHECK                                             
         31        INIT_FCALL                                               'assert'
         32        INIT_FCALL                                               'isitstringy'
         33        NEW                                              $11     'stdClass'
         34        DO_FCALL                                      0          
         35        SEND_VAR                                                 $11
         36        DO_FCALL                                      0  $13     
         37        TYPE_CHECK                                    4  ~14     $13
         38        SEND_VAL                                                 ~14
         39        SEND_VAL                                                 'assert%28isItStringy%28new+stdClass%28%29%29+%3D%3D%3D+false%29'
         40        DO_ICALL                                                 
         41      > RETURN                                                   1

Function isitstringy:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RRKkp
function name:  isItStringy
number of ops:  14
compiled vars:  !0 = $possibleStringType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        TYPE_CHECK                                   64          !0
          2      > JMPZ                                                     ~1, ->4
   16     3    > > RETURN                                                   <true>
   19     4    >   INIT_FCALL                                               'is_callable'
          5        INIT_ARRAY                                       ~2      !0
          6        ADD_ARRAY_ELEMENT                                ~2      '__toString'
          7        SEND_VAL                                                 ~2
          8        DO_ICALL                                         $3      
          9      > JMPZ                                                     $3, ->11
   20    10    > > RETURN                                                   <true>
   23    11    > > RETURN                                                   <false>
   24    12*       VERIFY_RETURN_TYPE                                       
         13*     > 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/RRKkp
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:
164.99 ms | 1453 KiB | 19 Q