3v4l.org

run code in 300+ PHP versions simultaneously
<?php $score = 64; $firstName = 'Jack'; $lastName = 'Saliv'; $age = 21; $expected = 'FFFEFF404A00610063006B00530061006C00690076FFFEFF15'; $expectedCorrected = 'FFFEFF404A00610063006B00530061006C0069007600FFFEFF15'; // Convert to UTF-16LE and get hex, https://stackoverflow.com/a/16080439/231316 $nameAsUtf16LE = unpack('H*', mb_convert_encoding($firstName.$lastName, 'UTF-16LE', 'UTF-8')); // UTF-16LE BOM $utf16LeBom = 'FFFE'; // Convert to hex strings $scoreAsHex = dechex($score); $ageAsHex = dechex($age); $finalString = sprintf( '%1$s%2$s%3$s', $utf16LeBom.$scoreAsHex, strtoupper($nameAsUtf16LE[1]), // This is 1-based, not 0-based $utf16LeBom.$ageAsHex, ); $numberPadding = 'FF'; $finalStringWithNumbersPadded = sprintf( '%1$s%2$s%3$s', $utf16LeBom.$numberPadding.$scoreAsHex, strtoupper($nameAsUtf16LE[1]), // This is 1-based, not 0-based $utf16LeBom.$numberPadding.$ageAsHex, ); echo 'Calculated : '.$finalString; echo PHP_EOL; echo 'Padded : '.$finalStringWithNumbersPadded; echo PHP_EOL; echo 'Expected : '.$expected; echo PHP_EOL; echo 'Expected Corrected : '.$expectedCorrected; assert($finalStringWithNumbersPadded === $expectedCorrected);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XTdjA
function name:  (null)
number of ops:  73
compiled vars:  !0 = $score, !1 = $firstName, !2 = $lastName, !3 = $age, !4 = $expected, !5 = $expectedCorrected, !6 = $nameAsUtf16LE, !7 = $utf16LeBom, !8 = $scoreAsHex, !9 = $ageAsHex, !10 = $finalString, !11 = $numberPadding, !12 = $finalStringWithNumbersPadded
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 64
    4     1        ASSIGN                                                   !1, 'Jack'
    5     2        ASSIGN                                                   !2, 'Saliv'
    6     3        ASSIGN                                                   !3, 21
    8     4        ASSIGN                                                   !4, 'FFFEFF404A00610063006B00530061006C00690076FFFEFF15'
    9     5        ASSIGN                                                   !5, 'FFFEFF404A00610063006B00530061006C0069007600FFFEFF15'
   12     6        INIT_FCALL                                               'unpack'
          7        SEND_VAL                                                 'H%2A'
          8        INIT_FCALL                                               'mb_convert_encoding'
          9        CONCAT                                           ~19     !1, !2
         10        SEND_VAL                                                 ~19
         11        SEND_VAL                                                 'UTF-16LE'
         12        SEND_VAL                                                 'UTF-8'
         13        DO_ICALL                                         $20     
         14        SEND_VAR                                                 $20
         15        DO_ICALL                                         $21     
         16        ASSIGN                                                   !6, $21
   15    17        ASSIGN                                                   !7, 'FFFE'
   18    18        INIT_FCALL                                               'dechex'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $24     
         21        ASSIGN                                                   !8, $24
   19    22        INIT_FCALL                                               'dechex'
         23        SEND_VAR                                                 !3
         24        DO_ICALL                                         $26     
         25        ASSIGN                                                   !9, $26
   21    26        INIT_FCALL                                               'sprintf'
   22    27        SEND_VAL                                                 '%251%24s%252%24s%253%24s'
   23    28        CONCAT                                           ~28     !7, !8
         29        SEND_VAL                                                 ~28
   24    30        INIT_FCALL                                               'strtoupper'
         31        FETCH_DIM_R                                      ~29     !6, 1
         32        SEND_VAL                                                 ~29
         33        DO_ICALL                                         $30     
         34        SEND_VAR                                                 $30
   25    35        CONCAT                                           ~31     !7, !9
         36        SEND_VAL                                                 ~31
   21    37        DO_ICALL                                         $32     
         38        ASSIGN                                                   !10, $32
   28    39        ASSIGN                                                   !11, 'FF'
   29    40        INIT_FCALL                                               'sprintf'
   30    41        SEND_VAL                                                 '%251%24s%252%24s%253%24s'
   31    42        CONCAT                                           ~35     !7, !11
         43        CONCAT                                           ~36     ~35, !8
         44        SEND_VAL                                                 ~36
   32    45        INIT_FCALL                                               'strtoupper'
         46        FETCH_DIM_R                                      ~37     !6, 1
         47        SEND_VAL                                                 ~37
         48        DO_ICALL                                         $38     
         49        SEND_VAR                                                 $38
   33    50        CONCAT                                           ~39     !7, !11
         51        CONCAT                                           ~40     ~39, !9
         52        SEND_VAL                                                 ~40
   29    53        DO_ICALL                                         $41     
         54        ASSIGN                                                   !12, $41
   36    55        CONCAT                                           ~43     'Calculated+++++++++%3A+', !10
         56        ECHO                                                     ~43
   37    57        ECHO                                                     '%0A'
   38    58        CONCAT                                           ~44     'Padded+++++++++++++%3A+', !12
         59        ECHO                                                     ~44
   39    60        ECHO                                                     '%0A'
   40    61        CONCAT                                           ~45     'Expected+++++++++++%3A+', !4
         62        ECHO                                                     ~45
   41    63        ECHO                                                     '%0A'
   42    64        CONCAT                                           ~46     'Expected+Corrected+%3A+', !5
         65        ECHO                                                     ~46
   44    66        ASSERT_CHECK                                             
         67        INIT_FCALL                                               'assert'
         68        IS_IDENTICAL                                     ~47     !12, !5
         69        SEND_VAL                                                 ~47
         70        SEND_VAL                                                 'assert%28%24finalStringWithNumbersPadded+%3D%3D%3D+%24expectedCorrected%29'
         71        DO_ICALL                                                 
         72      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.56 ms | 1008 KiB | 19 Q