3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace efiku; class Book { private $name; private $author; private $codeNumber; /** * Book constructor. * @param string $name * @param string $author * @param int $codeNumber */ public function __construct(string $name, string $author, int $codeNumber) { $this->name = $name; $this->author = $author; $this->codeNumber = $codeNumber; } /** * @return string */ public function getName() : string { return $this->name; } /** * @return string */ public function getAuthor() : string { return $this->author; } /** * @return int */ public function getCodeNumber() : int { return $this->codeNumber; } public function __toString() { return $this->name . " --- " . $this->author . " --- " . $this->codeNumber; } } use efiku\Book; $arrayOfBooks = []; // Generowanie tablicy z książkami foreach (range(1, 20) as $number) { $arrayOfBooks["book.{$number}"] = new Book( "PHP {$number}", "Podręcznik profesjonalisty! wydanie:{$number}", mt_rand(1, $number + 1 * 3) ); } // Sortujemy z użyciem wbudowanego mechanizmu asort($arrayOfBooks); foreach ($arrayOfBooks as $book) { echo $book . PHP_EOL; } ///////////////////////////////////////////////////// echo "\nSORTUJEMY Według Naszego mechanizmu\n\n"; uasort($arrayOfBooks, function (Book $first, Book $second) { $firstEditionNumber = (int)substr(strrchr($first->getAuthor(), ":"), 1); $secondEditionNumber = (int)substr(strrchr($second->getAuthor(), ":"), 1); return $firstEditionNumber <=> $secondEditionNumber; }); foreach ($arrayOfBooks as $book) { echo $book . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 27
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 37
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 37
2 jumps found. (Code = 77) Position 1 = 45, Position 2 = 50
Branch analysis from position: 45
2 jumps found. (Code = 78) Position 1 = 46, Position 2 = 50
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 37
Branch analysis from position: 27
filename:       /in/C5cjd
function name:  (null)
number of ops:  52
compiled vars:  !0 = $arrayOfBooks, !1 = $number, !2 = $book
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_CLASS                                            'efiku%5Cbook'
   55     1        ASSIGN                                                   !0, <array>
   58     2        INIT_NS_FCALL_BY_NAME                                    'efiku%5Crange'
          3        SEND_VAL_EX                                              1
          4        SEND_VAL_EX                                              20
          5        DO_FCALL                                      0  $4      
          6      > FE_RESET_R                                       $5      $4, ->27
          7    > > FE_FETCH_R                                               $5, !1, ->27
   59     8    >   NOP                                                      
          9        FAST_CONCAT                                      ~6      'book.', !1
         10        NEW                                              $8      'efiku%5CBook'
   60    11        NOP                                                      
         12        FAST_CONCAT                                      ~9      'PHP+', !1
         13        SEND_VAL_EX                                              ~9
   61    14        NOP                                                      
         15        FAST_CONCAT                                      ~10     'Podr%C4%99cznik+profesjonalisty%21+wydanie%3A', !1
         16        SEND_VAL_EX                                              ~10
   62    17        INIT_NS_FCALL_BY_NAME                                    'efiku%5Cmt_rand'
         18        SEND_VAL_EX                                              1
         19        ADD                                              ~11     !1, 3
         20        SEND_VAL_EX                                              ~11
         21        DO_FCALL                                      0  $12     
         22        SEND_VAR_NO_REF_EX                                       $12
         23        DO_FCALL                                      0          
   59    24        ASSIGN_DIM                                               !0, ~6
   62    25        OP_DATA                                                  $8
   58    26      > JMP                                                      ->7
         27    >   FE_FREE                                                  $5
   67    28        INIT_NS_FCALL_BY_NAME                                    'efiku%5Casort'
         29        SEND_VAR_EX                                              !0
         30        DO_FCALL                                      0          
   69    31      > FE_RESET_R                                       $15     !0, ->37
         32    > > FE_FETCH_R                                               $15, !2, ->37
   70    33    >   FETCH_CONSTANT                                   ~16     'efiku%5CPHP_EOL'
         34        CONCAT                                           ~17     !2, ~16
         35        ECHO                                                     ~17
   69    36      > JMP                                                      ->32
         37    >   FE_FREE                                                  $15
   75    38        ECHO                                                     '%0ASORTUJEMY+Wed%C5%82ug+Naszego+mechanizmu%0A%0A'
   77    39        INIT_NS_FCALL_BY_NAME                                    'efiku%5Cuasort'
         40        SEND_VAR_EX                                              !0
         41        DECLARE_LAMBDA_FUNCTION                                  '%00efiku%5C%7Bclosure%7D%2Fin%2FC5cjd%3A77%241'
   81    42        SEND_VAL_EX                                              ~18
         43        DO_FCALL                                      0          
   83    44      > FE_RESET_R                                       $20     !0, ->50
         45    > > FE_FETCH_R                                               $20, !2, ->50
   85    46    >   FETCH_CONSTANT                                   ~21     'efiku%5CPHP_EOL'
         47        CONCAT                                           ~22     !2, ~21
         48        ECHO                                                     ~22
   83    49      > JMP                                                      ->45
         50    >   FE_FREE                                                  $20
   86    51      > RETURN                                                   1

Function %00efiku%5C%7Bclosure%7D%2Fin%2FC5cjd%3A77%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C5cjd
function name:  efiku\{closure}
number of ops:  29
compiled vars:  !0 = $first, !1 = $second, !2 = $firstEditionNumber, !3 = $secondEditionNumber
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   78     2        INIT_NS_FCALL_BY_NAME                                    'efiku%5Csubstr'
          3        INIT_NS_FCALL_BY_NAME                                    'efiku%5Cstrrchr'
          4        INIT_METHOD_CALL                                         !0, 'getAuthor'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR_NO_REF_EX                                       $4
          7        SEND_VAL_EX                                              '%3A'
          8        DO_FCALL                                      0  $5      
          9        SEND_VAR_NO_REF_EX                                       $5
         10        SEND_VAL_EX                                              1
         11        DO_FCALL                                      0  $6      
         12        CAST                                          4  ~7      $6
         13        ASSIGN                                                   !2, ~7
   79    14        INIT_NS_FCALL_BY_NAME                                    'efiku%5Csubstr'
         15        INIT_NS_FCALL_BY_NAME                                    'efiku%5Cstrrchr'
         16        INIT_METHOD_CALL                                         !1, 'getAuthor'
         17        DO_FCALL                                      0  $9      
         18        SEND_VAR_NO_REF_EX                                       $9
         19        SEND_VAL_EX                                              '%3A'
         20        DO_FCALL                                      0  $10     
         21        SEND_VAR_NO_REF_EX                                       $10
         22        SEND_VAL_EX                                              1
         23        DO_FCALL                                      0  $11     
         24        CAST                                          4  ~12     $11
         25        ASSIGN                                                   !3, ~12
   80    26        SPACESHIP                                        ~14     !2, !3
         27      > RETURN                                                   ~14
   81    28*     > RETURN                                                   null

End of function %00efiku%5C%7Bclosure%7D%2Fin%2FC5cjd%3A77%241

Class efiku\Book:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C5cjd
function name:  __construct
number of ops:  10
compiled vars:  !0 = $name, !1 = $author, !2 = $codeNumber
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   18     3        ASSIGN_OBJ                                               'name'
          4        OP_DATA                                                  !0
   19     5        ASSIGN_OBJ                                               'author'
          6        OP_DATA                                                  !1
   20     7        ASSIGN_OBJ                                               'codeNumber'
          8        OP_DATA                                                  !2
   21     9      > RETURN                                                   null

End of function __construct

Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C5cjd
function name:  getName
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   29     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getname

Function getauthor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C5cjd
function name:  getAuthor
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   FETCH_OBJ_R                                      ~0      'author'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   37     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getauthor

Function getcodenumber:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C5cjd
function name:  getCodeNumber
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   FETCH_OBJ_R                                      ~0      'codeNumber'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   45     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getcodenumber

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C5cjd
function name:  __toString
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1        CONCAT                                           ~1      ~0, '+---+'
          2        FETCH_OBJ_R                                      ~2      'author'
          3        CONCAT                                           ~3      ~1, ~2
          4        CONCAT                                           ~4      ~3, '+---+'
          5        FETCH_OBJ_R                                      ~5      'codeNumber'
          6        CONCAT                                           ~6      ~4, ~5
          7        VERIFY_RETURN_TYPE                                       ~6
          8      > RETURN                                                   ~6
   50     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function __tostring

End of class efiku\Book.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.53 ms | 1408 KiB | 25 Q