3v4l.org

run code in 500+ PHP versions simultaneously
<?php // TimeFormat is only present to demonstrate a mistake. enum TimeFormat : string { case Short = 'concise'; case Long = 'full'; } // String 'long' and 'short' were the options before refactoring. // Always falling back to 'long' on something invalid. Never throwing or aborting the application. enum DateFormat : string { case Long = 'long'; case Abbreviated = 'short'; } function FormatCurrentDate($dateFormat = 'long') { // This should not throw. // // If a mistake is made, and somewhere a date time is presented in long format, // where a short format is wanted, that is not a reason to throw, aborting the application. // // The result of such a mistake is that in the browser maybe some text looks somewhat distorted. // Which is annoying, but not show stopping. $dateFormat = DateFormat::tryFrom($dateFormat) ?? DateFormat::Long; var_dump($dateFormat); } FormatCurrentDate('short'); // old style FormatCurrentDate(null); // sometimes the database contains NULL values FormatCurrentDate(); // maybe valid, maybe a mistake. It is unclear because no explicit value is given. More context is needed. FormatCurrentDate(DateFormat::Long); // new style FormatCurrentDate(TimeFormat::Short); // a mistake. But not a reason to throw, aborting the application. /* ------------------------------------------------ */ /* Not a reason to throw, aborting the application. */ /* ------------------------------------------------ */ $setting = new DateTimeImmutable(); // assigned somewhere else, in another .php file. The wrong setting was retrieved. FormatCurrentDate($setting); // maybe valid, maybe a mistake. Because $setting could be anything. /* ----------------------------------------------- */ /* Not a reason to assume $format is always valid. */ /* ------------------------------------------------ */ $setting = 'short'; // assigned somewhere else, in another .php file. FormatCurrentDate($setting); // maybe valid, maybe a mistake. Because $setting could be anything.
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Pmaph
function name:  (null)
number of ops:  29
compiled vars:  !0 = $setting
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   DECLARE_CLASS                                                'timeformat'
   12     1        DECLARE_CLASS                                                'dateformat'
   33     2        INIT_FCALL                                                   'formatcurrentdate'
          3        SEND_VAL                                                     'short'
          4        DO_FCALL                                          0          
   34     5        INIT_FCALL                                                   'formatcurrentdate'
          6        SEND_VAL                                                     null
          7        DO_FCALL                                          0          
   35     8        INIT_FCALL                                                   'formatcurrentdate'
          9        DO_FCALL                                          0          
   36    10        INIT_FCALL                                                   'formatcurrentdate'
         11        FETCH_CLASS_CONSTANT                                 ~4      'DateFormat', 'Long'
         12        SEND_VAL                                                     ~4
         13        DO_FCALL                                          0          
   37    14        INIT_FCALL                                                   'formatcurrentdate'
         15        FETCH_CLASS_CONSTANT                                 ~6      'TimeFormat', 'Short'
         16        SEND_VAL                                                     ~6
         17        DO_FCALL                                          0          
   42    18        NEW                                                  $8      'DateTimeImmutable'
         19        DO_FCALL                                          0          
         20        ASSIGN                                                       !0, $8
   43    21        INIT_FCALL                                                   'formatcurrentdate'
         22        SEND_VAR                                                     !0
         23        DO_FCALL                                          0          
   48    24        ASSIGN                                                       !0, 'short'
   49    25        INIT_FCALL                                                   'formatcurrentdate'
         26        SEND_VAR                                                     !0
         27        DO_FCALL                                          0          
         28      > RETURN                                                       1

Function formatcurrentdate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Pmaph
function name:  FormatCurrentDate
number of ops:  12
compiled vars:  !0 = $dateFormat
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   RECV_INIT                                            !0      'long'
   28     1        INIT_STATIC_METHOD_CALL                                      'DateFormat', 'tryFrom'
          2        SEND_VAR_EX                                                  !0
          3        DO_FCALL                                          0  $1      
          4        COALESCE                                             ~2      $1
          5        FETCH_CLASS_CONSTANT                                 ~3      'DateFormat', 'Long'
          6        QM_ASSIGN                                            ~2      ~3
          7        ASSIGN                                                       !0, ~2
   30     8        INIT_FCALL                                                   'var_dump'
          9        SEND_VAR                                                     !0
         10        DO_ICALL                                                     
   31    11      > RETURN                                                       null

End of function formatcurrentdate

Class TimeFormat: [no user functions]
Class DateFormat: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
130.84 ms | 485 KiB | 15 Q