3v4l.org

run code in 300+ PHP versions simultaneously
<?php $indexes = [ 26 => ["namespace" => "X\\Y\\Zed"], 9 => ["namespace" => "A\\B\\See"], 3 => ["namespace" => "A\\B\\Bee"], 38 => ["namespace" => "A\\B\\C\\Dee"], 51 => ["namespace" => "X\\Wye"], 16 => ["namespace" => "A\\Sea"], 12 => ["namespace" => "A\\Bees"], ]; uasort( $indexes, static function (array $a, array $b) { $aPath = $a['namespace']; $bPath = $b['namespace']; // Just in case there are duplicates if ($aPath === $bPath) { return 0; } // Break into parts $aParts = explode('\\', $aPath); $bParts = explode('\\', $bPath); // If we only have a single thing then it is a root-level, just compare the item if (1 === count($aParts) && 1 === count($bParts)) { return $aPath <=> $bPath; } // Get the class and namespace (file and folder) parts $aClass = array_pop($aParts); $bClass = array_pop($bParts); $aNamespace = implode('\\', $aParts); $bNamespace = implode('\\', $bParts); // If the namespaces are the same, sort by class name if ($aNamespace === $bNamespace) { return $aClass <=> $bClass; } // If the first namespace _starts_ with the second namespace, sort it first if (0 === mb_strpos($aNamespace, $bNamespace)) { return -1; } // Same as above but the other way if (0 === mb_strpos($bNamespace, $aNamespace)) { return 1; } // Just only by namespace return $aNamespace <=> $bNamespace; } ); $expected = [ 38 => ["namespace" => "A\\B\\C\\Dee"], 3 => ["namespace" => "A\\B\\Bee"], 9 => ["namespace" => "A\\B\\See"], 12 => ["namespace" => "A\\Bees"], 16 => ["namespace" => "A\\Sea"], 26 => ["namespace" => "X\\Y\\Zed"], 51 => ["namespace" => "X\\Wye"], ]; assert($indexes === $expected);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oCNgj
function name:  (null)
number of ops:  14
compiled vars:  !0 = $indexes, !1 = $expected
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   13     1        INIT_FCALL                                               'uasort'
   14     2        SEND_REF                                                 !0
   15     3        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   58     4        SEND_VAL                                                 ~3
   13     5        DO_ICALL                                                 
   61     6        ASSIGN                                                   !1, <array>
   71     7        ASSERT_CHECK                                             
          8        INIT_FCALL                                               'assert'
          9        IS_IDENTICAL                                     ~6      !0, !1
         10        SEND_VAL                                                 ~6
         11        SEND_VAL                                                 'assert%28%24indexes+%3D%3D%3D+%24expected%29'
         12        DO_ICALL                                                 
         13      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 50
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 57
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 64
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/oCNgj
function name:  {closure}
number of ops:  67
compiled vars:  !0 = $a, !1 = $b, !2 = $aPath, !3 = $bPath, !4 = $aParts, !5 = $bParts, !6 = $aClass, !7 = $bClass, !8 = $aNamespace, !9 = $bNamespace
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        FETCH_DIM_R                                      ~10     !0, 'namespace'
          3        ASSIGN                                                   !2, ~10
   18     4        FETCH_DIM_R                                      ~12     !1, 'namespace'
          5        ASSIGN                                                   !3, ~12
   21     6        IS_IDENTICAL                                             !2, !3
          7      > JMPZ                                                     ~14, ->9
   22     8    > > RETURN                                                   0
   26     9    >   INIT_FCALL                                               'explode'
         10        SEND_VAL                                                 '%5C'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $15     
         13        ASSIGN                                                   !4, $15
   27    14        INIT_FCALL                                               'explode'
         15        SEND_VAL                                                 '%5C'
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $17     
         18        ASSIGN                                                   !5, $17
   30    19        COUNT                                            ~19     !4
         20        IS_IDENTICAL                                     ~20     ~19, 1
         21      > JMPZ_EX                                          ~20     ~20, ->25
         22    >   COUNT                                            ~21     !5
         23        IS_IDENTICAL                                     ~22     ~21, 1
         24        BOOL                                             ~20     ~22
         25    > > JMPZ                                                     ~20, ->28
   31    26    >   SPACESHIP                                        ~23     !2, !3
         27      > RETURN                                                   ~23
   35    28    >   INIT_FCALL                                               'array_pop'
         29        SEND_REF                                                 !4
         30        DO_ICALL                                         $24     
         31        ASSIGN                                                   !6, $24
   36    32        INIT_FCALL                                               'array_pop'
         33        SEND_REF                                                 !5
         34        DO_ICALL                                         $26     
         35        ASSIGN                                                   !7, $26
   38    36        INIT_FCALL                                               'implode'
         37        SEND_VAL                                                 '%5C'
         38        SEND_VAR                                                 !4
         39        DO_ICALL                                         $28     
         40        ASSIGN                                                   !8, $28
   39    41        INIT_FCALL                                               'implode'
         42        SEND_VAL                                                 '%5C'
         43        SEND_VAR                                                 !5
         44        DO_ICALL                                         $30     
         45        ASSIGN                                                   !9, $30
   42    46        IS_IDENTICAL                                             !8, !9
         47      > JMPZ                                                     ~32, ->50
   43    48    >   SPACESHIP                                        ~33     !6, !7
         49      > RETURN                                                   ~33
   47    50    >   INIT_FCALL                                               'mb_strpos'
         51        SEND_VAR                                                 !8
         52        SEND_VAR                                                 !9
         53        DO_ICALL                                         $34     
         54        IS_IDENTICAL                                             $34, 0
         55      > JMPZ                                                     ~35, ->57
   48    56    > > RETURN                                                   -1
   52    57    >   INIT_FCALL                                               'mb_strpos'
         58        SEND_VAR                                                 !9
         59        SEND_VAR                                                 !8
         60        DO_ICALL                                         $36     
         61        IS_IDENTICAL                                             $36, 0
         62      > JMPZ                                                     ~37, ->64
   53    63    > > RETURN                                                   1
   57    64    >   SPACESHIP                                        ~38     !8, !9
         65      > RETURN                                                   ~38
   58    66*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
678.53 ms | 1014 KiB | 19 Q