3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Script to check whether current() takes its parameter by reference or by value */ if (defined('HHVM_VERSION')) { exit; } // adapted from http://php.net/manual/en/language.references.php#99644 $g_refcount_added = 0; function refcount($var) { ob_start(); debug_zval_dump($var); $dump = ob_get_clean(); $matches = array(); preg_match('/refcount\(([0-9]+)/', $dump, $matches); $count = $matches[1]; global $g_refcount_added; return $count - $g_refcount_added; } // configure our refcount function $array = array('key' => 'value'); $refcount_expected = 1; $refcount_actual = refcount($array); // 3 in PHP 7.0, 4 in other versions $g_refcount_added = $refcount_actual - $refcount_expected; unset($refcount_actual, $refcount_expected, $array); // end of configure our refcount function function print_refcounts($label, $orig_rc, $copy_rc = null) { if ($copy_rc === null) { printf("%s : orig %d %s (%s)\n", $label, $orig_rc, " ", 'alone'); } else { printf("%s : orig %d, copy %d (%s)\n", $label, $orig_rc, $copy_rc, $copy_rc > 1 ? 'sharing' : 'separated'); } } $orig = array('foo' => 'bar'); print_refcounts("initially ", refcount($orig)); $copy = $orig; print_refcounts("after copy", refcount($orig), refcount($copy)); current($copy); // if the argument is passed by reference, PHP separates $copy and $orig print_refcounts("after call", refcount($orig), refcount($copy));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 3
Branch analysis from position: 2
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0nBTK
function name:  (null)
number of ops:  50
compiled vars:  !0 = $g_refcount_added, !1 = $array, !2 = $refcount_expected, !3 = $refcount_actual, !4 = $orig, !5 = $copy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   DEFINED                                                  'HHVM_VERSION'
          1      > JMPZ                                                     ~6, ->3
    6     2    > > EXIT                                                     
   10     3    >   ASSIGN                                                   !0, 0
   27     4        ASSIGN                                                   !1, <array>
   28     5        ASSIGN                                                   !2, 1
   29     6        INIT_FCALL                                               'refcount'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $10     
          9        ASSIGN                                                   !3, $10
   30    10        SUB                                              ~12     !3, !2
         11        ASSIGN                                                   !0, ~12
   31    12        UNSET_CV                                                 !3
         13        UNSET_CV                                                 !2
         14        UNSET_CV                                                 !1
   43    15        ASSIGN                                                   !4, <array>
   44    16        INIT_FCALL                                               'print_refcounts'
         17        SEND_VAL                                                 'initially+'
         18        INIT_FCALL                                               'refcount'
         19        SEND_VAR                                                 !4
         20        DO_FCALL                                      0  $15     
         21        SEND_VAR                                                 $15
         22        DO_FCALL                                      0          
   45    23        ASSIGN                                                   !5, !4
   46    24        INIT_FCALL                                               'print_refcounts'
         25        SEND_VAL                                                 'after+copy'
         26        INIT_FCALL                                               'refcount'
         27        SEND_VAR                                                 !4
         28        DO_FCALL                                      0  $18     
         29        SEND_VAR                                                 $18
         30        INIT_FCALL                                               'refcount'
         31        SEND_VAR                                                 !5
         32        DO_FCALL                                      0  $19     
         33        SEND_VAR                                                 $19
         34        DO_FCALL                                      0          
   47    35        INIT_FCALL                                               'current'
         36        SEND_VAR                                                 !5
         37        DO_ICALL                                                 
   48    38        INIT_FCALL                                               'print_refcounts'
         39        SEND_VAL                                                 'after+call'
         40        INIT_FCALL                                               'refcount'
         41        SEND_VAR                                                 !4
         42        DO_FCALL                                      0  $22     
         43        SEND_VAR                                                 $22
         44        INIT_FCALL                                               'refcount'
         45        SEND_VAR                                                 !5
         46        DO_FCALL                                      0  $23     
         47        SEND_VAR                                                 $23
         48        DO_FCALL                                      0          
         49      > RETURN                                                   1

Function refcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0nBTK
function name:  refcount
number of ops:  21
compiled vars:  !0 = $var, !1 = $dump, !2 = $matches, !3 = $count, !4 = $g_refcount_added
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'ob_start'
          2        DO_ICALL                                                 
   14     3        INIT_FCALL                                               'debug_zval_dump'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   15     6        INIT_FCALL                                               'ob_get_clean'
          7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !1, $7
   17     9        ASSIGN                                                   !2, <array>
   18    10        INIT_FCALL                                               'preg_match'
         11        SEND_VAL                                                 '%2Frefcount%5C%28%28%5B0-9%5D%2B%29%2F'
         12        SEND_VAR                                                 !1
         13        SEND_REF                                                 !2
         14        DO_ICALL                                                 
   20    15        FETCH_DIM_R                                      ~11     !2, 1
         16        ASSIGN                                                   !3, ~11
   22    17        BIND_GLOBAL                                              !4, 'g_refcount_added'
   23    18        SUB                                              ~13     !3, !4
         19      > RETURN                                                   ~13
   24    20*     > RETURN                                                   null

End of function refcount

Function print_refcounts:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0nBTK
function name:  print_refcounts
number of ops:  26
compiled vars:  !0 = $label, !1 = $orig_rc, !2 = $copy_rc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   36     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~3, ->13
   37     5    >   INIT_FCALL                                               'printf'
          6        SEND_VAL                                                 '%25s+%3A+orig+%25d+++++++%25s+%28%25s%29%0A'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        SEND_VAL                                                 '+'
         10        SEND_VAL                                                 'alone'
         11        DO_ICALL                                                 
         12      > JMP                                                      ->25
   39    13    >   INIT_FCALL                                               'printf'
         14        SEND_VAL                                                 '%25s+%3A+orig+%25d%2C+copy+%25d+%28%25s%29%0A'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !1
         17        SEND_VAR                                                 !2
         18        IS_SMALLER                                               1, !2
         19      > JMPZ                                                     ~5, ->22
         20    >   QM_ASSIGN                                        ~6      'sharing'
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~6      'separated'
         23    >   SEND_VAL                                                 ~6
         24        DO_ICALL                                                 
   41    25    > > RETURN                                                   null

End of function print_refcounts

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.03 ms | 1407 KiB | 34 Q