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(); 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(); ?>
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to undefined function compareWebPageHTML() in /in/c9mG8:47 Stack trace: #0 /in/c9mG8(23): runAllUnitTests() #1 /in/c9mG8(51): runAllSamples() #2 {main} thrown in /in/c9mG8 on line 47
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Call to undefined function compareWebPageHTML() in /in/c9mG8 on line 47
Process exited with code 255.

preferences:
178.82 ms | 402 KiB | 213 Q