3v4l.org

run code in 500+ 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:  69
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        FRAMELESS_ICALL_1                dechex              ~24     !0
         19        ASSIGN                                                       !8, ~24
   19    20        FRAMELESS_ICALL_1                dechex              ~26     !3
         21        ASSIGN                                                       !9, ~26
   21    22        INIT_FCALL                                                   'sprintf'
   22    23        SEND_VAL                                                     '%251%24s%252%24s%253%24s'
   23    24        CONCAT                                               ~28     !7, !8
         25        SEND_VAL                                                     ~28
   24    26        INIT_FCALL                                                   'strtoupper'
         27        FETCH_DIM_R                                          ~29     !6, 1
         28        SEND_VAL                                                     ~29
         29        DO_ICALL                                             $30     
         30        SEND_VAR                                                     $30
   25    31        CONCAT                                               ~31     !7, !9
         32        SEND_VAL                                                     ~31
   21    33        DO_ICALL                                             $32     
         34        ASSIGN                                                       !10, $32
   28    35        ASSIGN                                                       !11, 'FF'
   29    36        INIT_FCALL                                                   'sprintf'
   30    37        SEND_VAL                                                     '%251%24s%252%24s%253%24s'
   31    38        CONCAT                                               ~35     !7, !11
         39        CONCAT                                               ~36     ~35, !8
         40        SEND_VAL                                                     ~36
   32    41        INIT_FCALL                                                   'strtoupper'
         42        FETCH_DIM_R                                          ~37     !6, 1
         43        SEND_VAL                                                     ~37
         44        DO_ICALL                                             $38     
         45        SEND_VAR                                                     $38
   33    46        CONCAT                                               ~39     !7, !11
         47        CONCAT                                               ~40     ~39, !9
         48        SEND_VAL                                                     ~40
   29    49        DO_ICALL                                             $41     
         50        ASSIGN                                                       !12, $41
   36    51        CONCAT                                               ~43     'Calculated+++++++++%3A+', !10
         52        ECHO                                                         ~43
   37    53        ECHO                                                         '%0A'
   38    54        CONCAT                                               ~44     'Padded+++++++++++++%3A+', !12
         55        ECHO                                                         ~44
   39    56        ECHO                                                         '%0A'
   40    57        CONCAT                                               ~45     'Expected+++++++++++%3A+', !4
         58        ECHO                                                         ~45
   41    59        ECHO                                                         '%0A'
   42    60        CONCAT                                               ~46     'Expected+Corrected+%3A+', !5
         61        ECHO                                                         ~46
   44    62        ASSERT_CHECK                                                 
         63        INIT_FCALL                                                   'assert'
         64        IS_IDENTICAL                                         ~47     !12, !5
         65        SEND_VAL                                                     ~47
         66        SEND_VAL                                                     'assert%28%24finalStringWithNumbersPadded+%3D%3D%3D+%24expectedCorrected%29'
         67        DO_ICALL                                                     
         68      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.22 ms | 1527 KiB | 19 Q