3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $a; protected $b; public $c; } class FooCountable implements \Countable { private $elements = [1,2,3]; public function count() { return count($this->elements); } } $tests = [ 'array' => [1,2,3], 'string' => 'hello world', 'number' => 123, 'iterator' => new \ArrayIterator([1,2,3]), 'countable' => new \FooCountable(), 'zero' => 0, 'string_zero' => '0', 'object' => new \Foo(), 'stdClass' => new \stdClass, 'null' => null, 'empty' => '', 'boolt' => true, 'boolf' => false ]; if (!\function_exists('is_countable')) { function is_countable($value) { echo 'used shim '; return \is_array($value) || $value instanceof \Countable; } } function countValid($array_or_countable, $mode = \COUNT_NORMAL) { if (\is_countable($array_or_countable)) { return \count($array_or_countable, $mode); } return null === $array_or_countable ? 0 : 1; } foreach($tests as $key => $test) { echo $key . ': ' . print_r(countValid($test), 1) . \PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 45
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 45
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
Branch analysis from position: 30
filename:       /in/i5KWH
function name:  (null)
number of ops:  47
compiled vars:  !0 = $tests, !1 = $test, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'foocountable'
   21     1        INIT_ARRAY                                       ~3      <array>, 'array'
   22     2        ADD_ARRAY_ELEMENT                                ~3      'hello+world', 'string'
   23     3        ADD_ARRAY_ELEMENT                                ~3      123, 'number'
   24     4        NEW                                              $4      'ArrayIterator'
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0          
          7        ADD_ARRAY_ELEMENT                                ~3      $4, 'iterator'
   25     8        NEW                                              $6      'FooCountable'
          9        DO_FCALL                                      0          
         10        ADD_ARRAY_ELEMENT                                ~3      $6, 'countable'
   26    11        ADD_ARRAY_ELEMENT                                ~3      0, 'zero'
   27    12        ADD_ARRAY_ELEMENT                                ~3      '0', 'string_zero'
   28    13        NEW                                              $8      'Foo'
         14        DO_FCALL                                      0          
         15        ADD_ARRAY_ELEMENT                                ~3      $8, 'object'
   29    16        NEW                                              $10     'stdClass'
         17        DO_FCALL                                      0          
         18        ADD_ARRAY_ELEMENT                                ~3      $10, 'stdClass'
   21    19        ADD_ARRAY_ELEMENT                                ~3      null, 'null'
   31    20        ADD_ARRAY_ELEMENT                                ~3      '', 'empty'
   21    21        ADD_ARRAY_ELEMENT                                ~3      <true>, 'boolt'
         22        ADD_ARRAY_ELEMENT                                ~3      <false>, 'boolf'
   20    23        ASSIGN                                                   !0, ~3
   36    24        INIT_FCALL                                               'function_exists'
         25        SEND_VAL                                                 'is_countable'
         26        DO_ICALL                                         $13     
         27        BOOL_NOT                                         ~14     $13
         28      > JMPZ                                                     ~14, ->30
   37    29    >   DECLARE_FUNCTION                                         'is_countable'
   53    30    > > FE_RESET_R                                       $15     !0, ->45
         31    > > FE_FETCH_R                                       ~16     $15, !1, ->45
         32    >   ASSIGN                                                   !2, ~16
   54    33        CONCAT                                           ~18     !2, '%3A+'
         34        INIT_FCALL                                               'print_r'
         35        INIT_FCALL                                               'countvalid'
         36        SEND_VAR                                                 !1
         37        DO_FCALL                                      0  $19     
         38        SEND_VAR                                                 $19
         39        SEND_VAL                                                 1
         40        DO_ICALL                                         $20     
         41        CONCAT                                           ~21     ~18, $20
         42        CONCAT                                           ~22     ~21, '%0A'
         43        ECHO                                                     ~22
   53    44      > JMP                                                      ->31
         45    >   FE_FREE                                                  $15
   55    46      > RETURN                                                   1

Function %00is_countable%2Fin%2Fi5KWH%3A37%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/i5KWH
function name:  is_countable
number of ops:  8
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   39     1        ECHO                                                     'used+shim+'
   40     2        TYPE_CHECK                                  128  ~1      !0
          3      > JMPNZ_EX                                         ~1      ~1, ->6
          4    >   INSTANCEOF                                       ~2      !0, 'Countable'
          5        BOOL                                             ~1      ~2
          6    > > RETURN                                                   ~1
   41     7*     > RETURN                                                   null

End of function %00is_countable%2Fin%2Fi5KWH%3A37%241

Function countvalid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i5KWH
function name:  countValid
number of ops:  18
compiled vars:  !0 = $array_or_countable, !1 = $mode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
   46     2        INIT_FCALL                                               'is_countable'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5      > JMPZ                                                     $2, ->11
   47     6    >   INIT_FCALL                                               'count'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $3      
         10      > RETURN                                                   $3
   50    11    >   TYPE_CHECK                                    2          !0
         12      > JMPZ                                                     ~4, ->15
         13    >   QM_ASSIGN                                        ~5      0
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~5      1
         16    > > RETURN                                                   ~5
   51    17*     > RETURN                                                   null

End of function countvalid

Class Foo: [no user functions]
Class FooCountable:
Function count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i5KWH
function name:  count
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   FETCH_OBJ_R                                      ~0      'elements'
          1        COUNT                                            ~1      ~0
          2      > RETURN                                                   ~1
   17     3*     > RETURN                                                   null

End of function count

End of class FooCountable.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.48 ms | 1407 KiB | 22 Q