3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Card { private $suit; private $val; public function __construct($val, $suit) { $values = array( '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, '10' => 10, 'J' => 11, 'Q' => 12, 'K' => 13, 'A' => 14, ); $suits = array( 'H' => 'Hearts', 'C' => 'Clubs', 'D' => 'Diamonds', 'S' => 'Spades' ); $this->suit = $suits[$suit]; $this->val = $values[$val]; } public function getSuit() { return $this->suit; } public function getVal() { return $this->val; } } class Hand { private $cards; public function __construct($hand) { $cards = explode(' ', $hand); foreach ($cards as $card) { $val = substr($card, 0, -1); $suit = strtoupper(substr($card, -1)); $this->cards[] = new Card($val, $suit); } } public function getCards(){ return $this->cards; } public function getValues(){ foreach($this->cards as $card){ $output[] = $card->getVal(); } return $output; } public function isHighCard(){ $output = max($this->getValues()); return $output; } public function isKind(){ $x = max(array_count_values($this->getValues())); if($x == 2){ echo "Two of a kind"; } else if($x == 3){ echo "Three of a kind"; } if($x == 4){ echo "Four of a kind"; } } } $h = new Hand('9s 9h 7d Js 10c'); $x = $h->isKind(); // var_dump($x);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Gphv
function name:  (null)
number of ops:  8
compiled vars:  !0 = $h, !1 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   95     0  E >   NEW                                              $2      'Hand'
          1        SEND_VAL_EX                                              '9s+9h+7d+Js+10c'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   96     4        INIT_METHOD_CALL                                         !0, 'isKind'
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !1, $5
   98     7      > RETURN                                                   1

Class Card:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Gphv
function name:  __construct
number of ops:  11
compiled vars:  !0 = $val, !1 = $suit, !2 = $values, !3 = $suits
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        ASSIGN                                                   !2, <array>
   26     3        ASSIGN                                                   !3, <array>
   33     4        FETCH_DIM_R                                      ~7      !3, !1
          5        ASSIGN_OBJ                                               'suit'
          6        OP_DATA                                                  ~7
   34     7        FETCH_DIM_R                                      ~9      !2, !0
          8        ASSIGN_OBJ                                               'val'
          9        OP_DATA                                                  ~9
   35    10      > RETURN                                                   null

End of function __construct

Function getsuit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Gphv
function name:  getSuit
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   FETCH_OBJ_R                                      ~0      'suit'
          1      > RETURN                                                   ~0
   39     2*     > RETURN                                                   null

End of function getsuit

Function getval:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Gphv
function name:  getVal
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   FETCH_OBJ_R                                      ~0      'val'
          1      > RETURN                                                   ~0
   43     2*     > RETURN                                                   null

End of function getval

End of class Card.

Class Hand:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 30
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 30
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/0Gphv
function name:  __construct
number of ops:  32
compiled vars:  !0 = $hand, !1 = $cards, !2 = $card, !3 = $val, !4 = $suit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   51     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   53     6      > FE_RESET_R                                       $7      !1, ->30
          7    > > FE_FETCH_R                                               $7, !2, ->30
   54     8    >   INIT_FCALL                                               'substr'
          9        SEND_VAR                                                 !2
         10        SEND_VAL                                                 0
         11        SEND_VAL                                                 -1
         12        DO_ICALL                                         $8      
         13        ASSIGN                                                   !3, $8
   55    14        INIT_FCALL                                               'strtoupper'
         15        INIT_FCALL                                               'substr'
         16        SEND_VAR                                                 !2
         17        SEND_VAL                                                 -1
         18        DO_ICALL                                         $10     
         19        SEND_VAR                                                 $10
         20        DO_ICALL                                         $11     
         21        ASSIGN                                                   !4, $11
   56    22        NEW                                              $15     'Card'
         23        SEND_VAR_EX                                              !3
         24        SEND_VAR_EX                                              !4
         25        DO_FCALL                                      0          
         26        FETCH_OBJ_W                                      $13     'cards'
         27        ASSIGN_DIM                                               $13
         28        OP_DATA                                                  $15
   53    29      > JMP                                                      ->7
         30    >   FE_FREE                                                  $7
   59    31      > RETURN                                                   null

End of function __construct

Function getcards:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Gphv
function name:  getCards
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   FETCH_OBJ_R                                      ~0      'cards'
          1      > RETURN                                                   ~0
   63     2*     > RETURN                                                   null

End of function getcards

Function getvalues:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 8
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/0Gphv
function name:  getValues
number of ops:  11
compiled vars:  !0 = $card, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   FETCH_OBJ_R                                      ~2      'cards'
          1      > FE_RESET_R                                       $3      ~2, ->8
          2    > > FE_FETCH_R                                               $3, !0, ->8
   68     3    >   INIT_METHOD_CALL                                         !0, 'getVal'
          4        DO_FCALL                                      0  $5      
          5        ASSIGN_DIM                                               !1
          6        OP_DATA                                                  $5
   67     7      > JMP                                                      ->2
          8    >   FE_FREE                                                  $3
   70     9      > RETURN                                                   !1
   71    10*     > RETURN                                                   null

End of function getvalues

Function ishighcard:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Gphv
function name:  isHighCard
number of ops:  8
compiled vars:  !0 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   INIT_FCALL                                               'max'
          1        INIT_METHOD_CALL                                         'getValues'
          2        DO_FCALL                                      0  $1      
          3        SEND_VAR                                                 $1
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !0, $2
   75     6      > RETURN                                                   !0
   77     7*     > RETURN                                                   null

End of function ishighcard

Function iskind:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
Branch analysis from position: 19
Branch analysis from position: 16
filename:       /in/0Gphv
function name:  isKind
number of ops:  20
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   INIT_FCALL                                               'max'
          1        INIT_FCALL                                               'array_count_values'
          2        INIT_METHOD_CALL                                         'getValues'
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR                                                 $1
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                         $3      
          8        ASSIGN                                                   !0, $3
   81     9        IS_EQUAL                                                 !0, 2
         10      > JMPZ                                                     ~5, ->13
   82    11    >   ECHO                                                     'Two+of+a+kind'
         12      > JMP                                                      ->16
   85    13    >   IS_EQUAL                                                 !0, 3
         14      > JMPZ                                                     ~6, ->16
   86    15    >   ECHO                                                     'Three+of+a+kind'
   88    16    >   IS_EQUAL                                                 !0, 4
         17      > JMPZ                                                     ~7, ->19
   89    18    >   ECHO                                                     'Four+of+a+kind'
   91    19    > > RETURN                                                   null

End of function iskind

End of class Hand.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
194.64 ms | 1408 KiB | 23 Q