3v4l.org

run code in 500+ PHP versions simultaneously
#!/usr/bin/env php <?php /** * Une date au format "YYYY-MM-DD HH:II:SS" n'est pas absolue et peut correspondre à plusieurs timestamps. * Lors du passage à l'heure d'hiver on a cette correspondance : * * ts 1540684800 = 2018-10-28T02:00:00+02:00 * ts 1540688400 = 2018-10-28T02:00:00+01:00 * ts 1540692000 = 2018-10-28T03:00:00+01:00 * * php via sa fonction mktime() permet de générer un timestamp (en interprétant les données dans la timezone définie dans le script). * * J'ai remarqué qu'en fournissant "2018-10-28 02:00:00" (avec un TZ Europe/Paris) le timestamp retourné est celui de la 2ème tranche de 02h (1540688400) * Oui mais ce comportement a changé au cours des versions de php !!! * Depuis la 8.1.7 le timestamp retourné correspond maintenant à la 1ère tranche de 02h (1540684800) * * Test sur plusieurs versions : * https://3v4l.org/8rC1Y * * Alors oui ça part d'un bon sentiment d'éradiquer des bugs : * - https://www.php.net/ChangeLog-8.php#8.1.7 * - https://bugs.php.net/bug.php?id=68549 */ date_default_timezone_set('Europe/Paris'); $tz = date_default_timezone_get(); $datetime = '2018-10-28 02:00:00'; // ambigü car passage à l'heure d'hiver $year = (int) substr($datetime, 0, 4); $month = (int) substr($datetime, 5, 2); $day = (int) substr($datetime, 8, 2); $hour = (int) substr($datetime, 11, 2); $minute = (int) substr($datetime, 14, 2); $second = (int) substr($datetime, 17, 2); $ts = mktime($hour, $minute, $second, $month, $day, $year); $offset = intval(date('Z', $ts) / 3600); // pour Europe/Paris: +1 ou +2 echo $tz . ' ' . $datetime . ' : timestamp=' . $ts . ' offset=' . $offset . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DO9AE
function name:  (null)
number of ops:  56
compiled vars:  !0 = $tz, !1 = $datetime, !2 = $year, !3 = $month, !4 = $day, !5 = $hour, !6 = $minute, !7 = $second, !8 = $ts, !9 = $offset
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                                   'date_default_timezone_set'
          1        SEND_VAL                                                     'Europe%2FParis'
          2        DO_ICALL                                                     
   27     3        INIT_FCALL                                                   'date_default_timezone_get'
          4        DO_ICALL                                             $11     
          5        ASSIGN                                                       !0, $11
   29     6        ASSIGN                                                       !1, '2018-10-28+02%3A00%3A00'
   31     7        FRAMELESS_ICALL_3                substr              ~14     !1, 0
          8        OP_DATA                                                      4
          9        CAST                                              4  ~15     ~14
         10        ASSIGN                                                       !2, ~15
   32    11        FRAMELESS_ICALL_3                substr              ~17     !1, 5
         12        OP_DATA                                                      2
         13        CAST                                              4  ~18     ~17
         14        ASSIGN                                                       !3, ~18
   33    15        FRAMELESS_ICALL_3                substr              ~20     !1, 8
         16        OP_DATA                                                      2
         17        CAST                                              4  ~21     ~20
         18        ASSIGN                                                       !4, ~21
   34    19        FRAMELESS_ICALL_3                substr              ~23     !1, 11
         20        OP_DATA                                                      2
         21        CAST                                              4  ~24     ~23
         22        ASSIGN                                                       !5, ~24
   35    23        FRAMELESS_ICALL_3                substr              ~26     !1, 14
         24        OP_DATA                                                      2
         25        CAST                                              4  ~27     ~26
         26        ASSIGN                                                       !6, ~27
   36    27        FRAMELESS_ICALL_3                substr              ~29     !1, 17
         28        OP_DATA                                                      2
         29        CAST                                              4  ~30     ~29
         30        ASSIGN                                                       !7, ~30
   38    31        INIT_FCALL                                                   'mktime'
         32        SEND_VAR                                                     !5
         33        SEND_VAR                                                     !6
         34        SEND_VAR                                                     !7
         35        SEND_VAR                                                     !3
         36        SEND_VAR                                                     !4
         37        SEND_VAR                                                     !2
         38        DO_ICALL                                             $32     
         39        ASSIGN                                                       !8, $32
   39    40        INIT_FCALL                                                   'date'
         41        SEND_VAL                                                     'Z'
         42        SEND_VAR                                                     !8
         43        DO_ICALL                                             $34     
         44        DIV                                                  ~35     $34, 3600
         45        CAST                                              4  ~36     ~35
         46        ASSIGN                                                       !9, ~36
   41    47        CONCAT                                               ~38     !0, '+'
         48        CONCAT                                               ~39     ~38, !1
         49        CONCAT                                               ~40     ~39, '+%3A+timestamp%3D'
         50        CONCAT                                               ~41     ~40, !8
         51        CONCAT                                               ~42     ~41, '+offset%3D'
         52        CONCAT                                               ~43     ~42, !9
         53        CONCAT                                               ~44     ~43, '%0A'
         54        ECHO                                                         ~44
         55      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
181.94 ms | 3342 KiB | 17 Q