3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test implements Countable { public $prop1; private $propa=2; protected $propx=3; public $prop4 = array(1,2,3,4); public function Greet() { return 'hello world'; } public function getCount() { $res = (array) $this; return count($res); } public function count() { echo 'Trying to get the count ...'; return $this->getCount(); } } // per manual: ArrayObject constructed from array means all properties are public. $t = new Test; echo $t->Greet(),"\n"; echo count( (array) $t),"\n"; echo $t->getCount(),"\n"; echo count($t),"\n"; var_dump( get_object_vars($t) ); $a = (array) $t; echo count($ao = new ArrayObject($a)),"\n"; echo $ao->count(); echo is_countable($ao);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hft2j
function name:  (null)
number of ops:  42
compiled vars:  !0 = $t, !1 = $a, !2 = $ao
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'test'
   24     1        NEW                                              $3      'Test'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   25     4        INIT_METHOD_CALL                                         !0, 'Greet'
          5        DO_FCALL                                      0  $6      
          6        ECHO                                                     $6
          7        ECHO                                                     '%0A'
   26     8        CAST                                          7  ~7      !0
          9        COUNT                                            ~8      ~7
         10        ECHO                                                     ~8
         11        ECHO                                                     '%0A'
   27    12        INIT_METHOD_CALL                                         !0, 'getCount'
         13        DO_FCALL                                      0  $9      
         14        ECHO                                                     $9
         15        ECHO                                                     '%0A'
   28    16        COUNT                                            ~10     !0
         17        ECHO                                                     ~10
         18        ECHO                                                     '%0A'
   29    19        INIT_FCALL                                               'var_dump'
         20        INIT_FCALL                                               'get_object_vars'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $11     
         23        SEND_VAR                                                 $11
         24        DO_ICALL                                                 
   30    25        CAST                                          7  ~13     !0
         26        ASSIGN                                                   !1, ~13
   31    27        NEW                                              $15     'ArrayObject'
         28        SEND_VAR_EX                                              !1
         29        DO_FCALL                                      0          
         30        ASSIGN                                           ~17     !2, $15
         31        COUNT                                            ~18     ~17
         32        ECHO                                                     ~18
         33        ECHO                                                     '%0A'
   32    34        INIT_METHOD_CALL                                         !2, 'count'
         35        DO_FCALL                                      0  $19     
         36        ECHO                                                     $19
   33    37        INIT_FCALL                                               'is_countable'
         38        SEND_VAR                                                 !2
         39        DO_ICALL                                         $20     
         40        ECHO                                                     $20
         41      > RETURN                                                   1

Class Test:
Function greet:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hft2j
function name:  Greet
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E > > RETURN                                                   'hello+world'
   11     1*     > RETURN                                                   null

End of function greet

Function getcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hft2j
function name:  getCount
number of ops:  6
compiled vars:  !0 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_THIS                                       ~1      
          1        CAST                                          7  ~2      ~1
          2        ASSIGN                                                   !0, ~2
   15     3        COUNT                                            ~4      !0
          4      > RETURN                                                   ~4
   16     5*     > RETURN                                                   null

End of function getcount

Function count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hft2j
function name:  count
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ECHO                                                     'Trying+to+get+the+count+...'
   20     1        INIT_METHOD_CALL                                         'getCount'
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   21     4*     > RETURN                                                   null

End of function count

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.4 ms | 1400 KiB | 19 Q