3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Fiddle in response to StackOverflow question: https://stackoverflow.com/questions/69845122 // by HappyDog // According to the PHP documentation, returning false from an output-buffer // callback should result in the same result as returning the original input, // but this fiddle shows that returning false actually breaks the buffer if it // is 'cleaned'. The solution is to always return a string value. ////////////////////////////// // CALLBACKS // Returns false, which means 'use the buffer as supplied'. function ReturnFalse($Buffer, $Phase) { global $arrCallbacks; $arrCallbacks[] = array($Buffer, $Phase); return false; } // Returns the supplied buffer - result should be identical to returning false. function ReturnBuffer($Buffer, $Phase) { global $arrCallbacks; $arrCallbacks[] = array($Buffer, $Phase); return $Buffer; } ////////////////////////////// // TESTING CODE foreach (array("ReturnFalse", "ReturnBuffer") as $Callback) { $arrCallbacks = array(); print("== Testing " . $Callback . " ===\n"); ob_start($Callback); print("First\n"); ob_clean(); print("Second\n"); ob_end_flush(); print("\n"); var_dump($arrCallbacks); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 1, Position 2 = 20
Branch analysis from position: 1
2 jumps found. (Code = 78) Position 1 = 2, Position 2 = 20
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 1
Branch analysis from position: 1
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/66cai
function name:  (null)
number of ops:  22
compiled vars:  !0 = $Callback, !1 = $arrCallbacks
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E > > FE_RESET_R                                       $2      <array>, ->20
          1    > > FE_FETCH_R                                               $2, !0, ->20
   32     2    >   ASSIGN                                                   !1, <array>
   33     3        CONCAT                                           ~4      '%3D%3D+Testing+', !0
          4        CONCAT                                           ~5      ~4, '+%3D%3D%3D%0A'
          5        ECHO                                                     ~5
   35     6        INIT_FCALL                                               'ob_start'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                                 
   36     9        ECHO                                                     'First%0A'
   37    10        INIT_FCALL                                               'ob_clean'
         11        DO_ICALL                                                 
   38    12        ECHO                                                     'Second%0A'
   39    13        INIT_FCALL                                               'ob_end_flush'
         14        DO_ICALL                                                 
   41    15        ECHO                                                     '%0A'
   42    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
   31    19      > JMP                                                      ->1
         20    >   FE_FREE                                                  $2
   43    21      > RETURN                                                   1

Function returnfalse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/66cai
function name:  ReturnFalse
number of ops:  9
compiled vars:  !0 = $Buffer, !1 = $Phase, !2 = $arrCallbacks
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        BIND_GLOBAL                                              !2, 'arrCallbacks'
   17     3        INIT_ARRAY                                       ~4      !0
          4        ADD_ARRAY_ELEMENT                                ~4      !1
          5        ASSIGN_DIM                                               !2
          6        OP_DATA                                                  ~4
   18     7      > RETURN                                                   <false>
   19     8*     > RETURN                                                   null

End of function returnfalse

Function returnbuffer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/66cai
function name:  ReturnBuffer
number of ops:  9
compiled vars:  !0 = $Buffer, !1 = $Phase, !2 = $arrCallbacks
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2        BIND_GLOBAL                                              !2, 'arrCallbacks'
   24     3        INIT_ARRAY                                       ~4      !0
          4        ADD_ARRAY_ELEMENT                                ~4      !1
          5        ASSIGN_DIM                                               !2
          6        OP_DATA                                                  ~4
   25     7      > RETURN                                                   !0
   26     8*     > RETURN                                                   null

End of function returnbuffer

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.39 ms | 1400 KiB | 21 Q