3v4l.org

run code in 300+ PHP versions simultaneously
<?php /*** * EN: Code samples written in PHP 5 by Louis Fontaine, 2016 * Three simple code samples + unit tests, allowed to be distributed by Treffer Uitzendbureau. For ease * of distribution, all code is contained in a single file. * Sample one outputs HTML code for a very simple web page using some dynamic content. * Sample two ... * Sample three consists of excerpts from code currently in production at a former client, used to * geocode zipcodes by accessing a 3rd party web service and estimate the distance to a user's location. * * NL: Voorbeeldcode in PHP 5 door Louis Fontaine, 2016 * Drie simpele stukken voorbeeldcode + unit tests, uit te geven door Treffer Uitzendbureau. Om de code * makkelijker te kunnen verspreiden, is alles samengevoegd in één bestand. * Voorbeeld één geeft als output HTML code van een simpele webpagina met wat dynamische content. * Voorbeeld twee ... * Voorbeeld drie bestaat uit fragmenten van code die momenteel in productie zijn bij een voormalige cliënt * met als functie het geocoderen van postcodes met behulp van een 3rd party webservice en het schatten van * afstanden tot de huidige locatie van de gebruiker. ***/ function runAllSamples(){ sample1(); sample2(); sample3(); runAllUnitTests(); } function sample1(){ $pageWriter = new PageWriter(); $pageWriter->write(); } class PageWriter{ private $useRandom = false; function __construct($testMode = false){ $useRandom = !$testMode; } function write(){ ?> <?php } } function runAllUnitTests(){ $pageWriter = new PageWriter(false); $success = compareWebPageHTML($pageWriter.write()); echo 'Unit test PageWriter (sample one): ' . $success ? 'success' : 'failed'; } runAllSamples(); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3ocqM
function name:  (null)
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   INIT_FCALL                                               'runallsamples'
          1        DO_FCALL                                      0          
   55     2      > RETURN                                                   1

Function runallsamples:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3ocqM
function name:  runAllSamples
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL_BY_NAME                                       'sample1'
          1        DO_FCALL                                      0          
   23     2        INIT_FCALL_BY_NAME                                       'sample2'
          3        DO_FCALL                                      0          
   24     4        INIT_FCALL_BY_NAME                                       'sample3'
          5        DO_FCALL                                      0          
   25     6        INIT_FCALL_BY_NAME                                       'runAllUnitTests'
          7        DO_FCALL                                      0          
   26     8      > RETURN                                                   null

End of function runallsamples

Function sample1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3ocqM
function name:  sample1
number of ops:  6
compiled vars:  !0 = $pageWriter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   NEW                                              $1      'PageWriter'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   30     3        INIT_METHOD_CALL                                         !0, 'write'
          4        DO_FCALL                                      0          
   31     5      > RETURN                                                   null

End of function sample1

Function runallunittests:
Finding entry points
Branch analysis from position: 0
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/3ocqM
function name:  runAllUnitTests
number of ops:  18
compiled vars:  !0 = $pageWriter, !1 = $success
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   NEW                                              $2      'PageWriter'
          1        SEND_VAL_EX                                              <false>
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   49     4        INIT_FCALL_BY_NAME                                       'compareWebPageHTML'
          5        INIT_FCALL_BY_NAME                                       'write'
          6        DO_FCALL                                      0  $5      
          7        CONCAT                                           ~6      !0, $5
          8        SEND_VAL_EX                                              ~6
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !1, $7
   50    11        CONCAT                                           ~9      'Unit+test+PageWriter+%28sample+one%29%3A+', !1
         12      > JMPZ                                                     ~9, ->15
         13    >   QM_ASSIGN                                        ~10     'success'
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~10     'failed'
         16    >   ECHO                                                     ~10
   51    17      > RETURN                                                   null

End of function runallunittests

Class PageWriter:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3ocqM
function name:  __construct
number of ops:  4
compiled vars:  !0 = $testMode, !1 = $useRandom
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV_INIT                                        !0      <false>
   37     1        BOOL_NOT                                         ~2      !0
          2        ASSIGN                                                   !1, ~2
   38     3      > RETURN                                                   null

End of function __construct

Function write:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3ocqM
function name:  write
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   ECHO                                                     '++++%0A++++'
   44     1      > RETURN                                                   null

End of function write

End of class PageWriter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.13 ms | 1402 KiB | 14 Q