3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ToStringMadness { private $data; public function __construct($data) { $this->data = $data; } public function __toString() { $data = array_map(function($item) { return $item; }, $this->data); sort($data); $rs = implode('-', $data); echo $rs."\n"; return $rs; } } $a = [ new ToStringMadness(['c','b']), new ToStringMadness(['c','b','a']), new ToStringMadness(['a','b']), ]; sort($a); /* usort($a, function(array $itemA, array $itemB) { sort($itemA); sort($itemB); $itemA = implode('-', $itemA); $itemB = implode('-', $itemB); echo $itemA.' vs '.$itemB."\n"; return strcmp($itemA, $itemB); }); */ print_r($a);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LTMJ0
function name:  (null)
number of ops:  21
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'tostringmadness'
   21     1        NEW                                              $1      'ToStringMadness'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        INIT_ARRAY                                       ~3      $1
   22     5        NEW                                              $4      'ToStringMadness'
          6        SEND_VAL_EX                                              <array>
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~3      $4
   23     9        NEW                                              $6      'ToStringMadness'
         10        SEND_VAL_EX                                              <array>
         11        DO_FCALL                                      0          
         12        ADD_ARRAY_ELEMENT                                ~3      $6
   20    13        ASSIGN                                                   !0, ~3
   26    14        INIT_FCALL                                               'sort'
         15        SEND_REF                                                 !0
         16        DO_ICALL                                                 
   39    17        INIT_FCALL                                               'print_r'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FLTMJ0%3A11%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LTMJ0
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1      > RETURN                                                   !0
          2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FLTMJ0%3A11%240

Class ToStringMadness:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LTMJ0
function name:  __construct
number of ops:  4
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
    8     3      > RETURN                                                   null

End of function __construct

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LTMJ0
function name:  __toString
number of ops:  21
compiled vars:  !0 = $data, !1 = $rs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_FCALL                                               'array_map'
          1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FLTMJ0%3A11%240'
          2        SEND_VAL                                                 ~2
          3        FETCH_OBJ_R                                      ~3      'data'
          4        SEND_VAL                                                 ~3
          5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !0, $4
   12     7        INIT_FCALL                                               'sort'
          8        SEND_REF                                                 !0
          9        DO_ICALL                                                 
   13    10        INIT_FCALL                                               'implode'
         11        SEND_VAL                                                 '-'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $7      
         14        ASSIGN                                                   !1, $7
   14    15        CONCAT                                           ~9      !1, '%0A'
         16        ECHO                                                     ~9
   16    17        VERIFY_RETURN_TYPE                                       !1
         18      > RETURN                                                   !1
   17    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function __tostring

End of class ToStringMadness.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.17 ms | 1408 KiB | 22 Q