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); $data = array_merge($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); print_r($a); usort($a, function(array $itemA, array $itemB) { return strcmp((string)$itemA, (string)$itemB); });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K6YHT
function name:  (null)
number of ops:  26
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'tostringmadness'
   22     1        NEW                                              $1      'ToStringMadness'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        INIT_ARRAY                                       ~3      $1
   23     5        NEW                                              $4      'ToStringMadness'
          6        SEND_VAL_EX                                              <array>
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~3      $4
   24     9        NEW                                              $6      'ToStringMadness'
         10        SEND_VAL_EX                                              <array>
         11        DO_FCALL                                      0          
         12        ADD_ARRAY_ELEMENT                                ~3      $6
   21    13        ASSIGN                                                   !0, ~3
   27    14        INIT_FCALL                                               'sort'
         15        SEND_REF                                                 !0
         16        DO_ICALL                                                 
   29    17        INIT_FCALL                                               'print_r'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                                 
   31    20        INIT_FCALL                                               'usort'
         21        SEND_REF                                                 !0
         22        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FK6YHT%3A31%241'
   33    23        SEND_VAL                                                 ~11
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FK6YHT%3A31%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K6YHT
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $itemA, !1 = $itemB
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   32     2        INIT_FCALL                                               'strcmp'
          3        CAST                                          6  ~2      !0
          4        SEND_VAL                                                 ~2
          5        CAST                                          6  ~3      !1
          6        SEND_VAL                                                 ~3
          7        DO_ICALL                                         $4      
          8      > RETURN                                                   $4
   33     9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FK6YHT%3A31%241

Class ToStringMadness:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K6YHT
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/K6YHT
function name:  __toString
number of ops:  18
compiled vars:  !0 = $data, !1 = $rs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   INIT_FCALL                                               'array_merge'
          1        SEND_VAR                                                 !0
          2        DO_ICALL                                         $2      
          3        ASSIGN                                                   !0, $2
   13     4        INIT_FCALL                                               'sort'
          5        SEND_REF                                                 !0
          6        DO_ICALL                                                 
   14     7        INIT_FCALL                                               'implode'
          8        SEND_VAL                                                 '-'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $5      
         11        ASSIGN                                                   !1, $5
   15    12        CONCAT                                           ~7      !1, '%0A'
         13        ECHO                                                     ~7
   17    14        VERIFY_RETURN_TYPE                                       !1
         15      > RETURN                                                   !1
   18    16*       VERIFY_RETURN_TYPE                                       
         17*     > RETURN                                                   null

End of function __tostring

End of class ToStringMadness.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.38 ms | 1400 KiB | 25 Q