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 ]; 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; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nbJ1n
function name:  (null)
number of ops:  25
compiled vars:  !0 = $tests
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'foocountable'
   21     1        INIT_ARRAY                                       ~1      <array>, 'array'
   22     2        ADD_ARRAY_ELEMENT                                ~1      'hello+world', 'string'
   23     3        ADD_ARRAY_ELEMENT                                ~1      123, 'number'
   24     4        NEW                                              $2      'ArrayIterator'
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0          
          7        ADD_ARRAY_ELEMENT                                ~1      $2, 'iterator'
   25     8        NEW                                              $4      'FooCountable'
          9        DO_FCALL                                      0          
         10        ADD_ARRAY_ELEMENT                                ~1      $4, 'countable'
   26    11        ADD_ARRAY_ELEMENT                                ~1      0, 'zero'
   27    12        ADD_ARRAY_ELEMENT                                ~1      '0', 'string_zero'
   28    13        NEW                                              $6      'Foo'
         14        DO_FCALL                                      0          
         15        ADD_ARRAY_ELEMENT                                ~1      $6, 'object'
   29    16        NEW                                              $8      'stdClass'
         17        DO_FCALL                                      0          
         18        ADD_ARRAY_ELEMENT                                ~1      $8, 'stdClass'
   21    19        ADD_ARRAY_ELEMENT                                ~1      null, 'null'
   31    20        ADD_ARRAY_ELEMENT                                ~1      '', 'empty'
   21    21        ADD_ARRAY_ELEMENT                                ~1      <true>, 'boolt'
         22        ADD_ARRAY_ELEMENT                                ~1      <false>, 'boolf'
   20    23        ASSIGN                                                   !0, ~1
   44    24      > RETURN                                                   1

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/nbJ1n
function name:  countValid
number of ops:  18
compiled vars:  !0 = $array_or_countable, !1 = $mode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
   39     2        INIT_FCALL                                               'is_countable'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5      > JMPZ                                                     $2, ->11
   40     6    >   INIT_FCALL                                               'count'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $3      
         10      > RETURN                                                   $3
   43    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
   44    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/nbJ1n
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.59 ms | 1404 KiB | 17 Q