3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Card { protected $suit; protected $value; protected $suit_text; protected $value_text; protected $facedown = false; public function __construct($suit, $value) { $suits = array( 'H' => 'Hearts', 'C' => 'Clubs', 'D' => 'Diamonds', 'S' => 'Spades' ); $values = array( 'A' => 'Ace', '2' => 'Two', '3' => 'Three', '4' => 'Four', '5' => 'Five', '6' => 'Six', '7' => 'Seven', '8' => 'Eight', '9' => 'Nine', '10' => 'Ten', 'J' => 'Jack', 'Q' => 'Queen', 'K' => 'King' ); $this->suit = $suit; $this->value = $value; $this->suit_text = $suits[$suit]; $this->value_text = $values[$value]; } /** * @return string */ public function getSuit() { return $this->suit; } /** * @return string */ public function getValue() { return $this->value; } /** * @return string */ public function getAsText() { return $this->value_text.' of '.$this->suit_text; } /** * @return string */ public function getSuitAsText() { return $this->suit_text; } /** * @return string */ public function getValueAsText() { return $this->value_text; } /** * Generates HTML for the card * @param string $id * @return string */ public function getHtml($id = null) { $html = '<div id="'.$id.'" class="playing-card card-' .strtolower($this->getValue()) .strtolower($this->getSuit()).' '; if($this->facedown == true){$html .= 'playing-card-facedown ';} $html .= '"></div>'; return $html; } /** * @return string */ public function getJson() { $class = 'playing-card card-'.strtolower($this->getValue()).strtolower($this->getSuit()).' '; if($this->facedown == true){$class .= 'playing-card-facedown ';} $array = array( 'suit' => $this->getSuit(), 'value' => $this->getValue(), 'suit_text' => $this->getSuitAsText(), 'value_text' => $this->getValueAsText(), 'facedown' => $this->facedown, 'divclass' => $class ); return json_encode($array); } /** * Flips the card face up or face down */ public function flipCard() { if($this->facedown == false) { $this->facedown = true; } else { $this->facedown = false; } } /** * Flips the card face down */ public function flipFaceDown() { $this->facedown = true; } /** * Flips the card face up */ public function flipFaceUp() { $this->facedown = false; } /** * @return bool */ public function isFaceDown() { if($this->facedown == true) { return true; } return false; } } $cards = []; $hand = 'As Ks Qs Js 10s'; $array = explode(' ', $hand); foreach ($array as $card) { $val = substr($card, 0, -1); $suit = strtoupper(substr($card, -1)); $cards[] = new Card($suit, $val); } var_dump($cards);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 30
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 30
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/Y4kOF
function name:  (null)
number of ops:  35
compiled vars:  !0 = $cards, !1 = $hand, !2 = $array, !3 = $card, !4 = $val, !5 = $suit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  145     0  E >   ASSIGN                                                   !0, <array>
  146     1        ASSIGN                                                   !1, 'As+Ks+Qs+Js+10s'
  147     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !2, $8
  148     7      > FE_RESET_R                                       $10     !2, ->30
          8    > > FE_FETCH_R                                               $10, !3, ->30
  149     9    >   INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !3
         11        SEND_VAL                                                 0
         12        SEND_VAL                                                 -1
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !4, $11
  150    15        INIT_FCALL                                               'strtoupper'
         16        INIT_FCALL                                               'substr'
         17        SEND_VAR                                                 !3
         18        SEND_VAL                                                 -1
         19        DO_ICALL                                         $13     
         20        SEND_VAR                                                 $13
         21        DO_ICALL                                         $14     
         22        ASSIGN                                                   !5, $14
  151    23        NEW                                              $17     'Card'
         24        SEND_VAR_EX                                              !5
         25        SEND_VAR_EX                                              !4
         26        DO_FCALL                                      0          
         27        ASSIGN_DIM                                               !0
         28        OP_DATA                                                  $17
  148    29      > JMP                                                      ->8
         30    >   FE_FREE                                                  $10
  155    31        INIT_FCALL                                               'var_dump'
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                                 
         34      > RETURN                                                   1

Class Card:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y4kOF
function name:  __construct
number of ops:  15
compiled vars:  !0 = $suit, !1 = $value, !2 = $suits, !3 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        ASSIGN                                                   !2, <array>
   18     3        ASSIGN                                                   !3, <array>
   33     4        ASSIGN_OBJ                                               'suit'
          5        OP_DATA                                                  !0
   34     6        ASSIGN_OBJ                                               'value'
          7        OP_DATA                                                  !1
   35     8        FETCH_DIM_R                                      ~9      !2, !0
          9        ASSIGN_OBJ                                               'suit_text'
         10        OP_DATA                                                  ~9
   36    11        FETCH_DIM_R                                      ~11     !3, !1
         12        ASSIGN_OBJ                                               'value_text'
         13        OP_DATA                                                  ~11
   37    14      > 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/Y4kOF
function name:  getSuit
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   FETCH_OBJ_R                                      ~0      'suit'
          1      > RETURN                                                   ~0
   44     2*     > RETURN                                                   null

End of function getsuit

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

End of function getvalue

Function getastext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y4kOF
function name:  getAsText
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   FETCH_OBJ_R                                      ~0      'value_text'
          1        CONCAT                                           ~1      ~0, '+of+'
          2        FETCH_OBJ_R                                      ~2      'suit_text'
          3        CONCAT                                           ~3      ~1, ~2
          4      > RETURN                                                   ~3
   58     5*     > RETURN                                                   null

End of function getastext

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

End of function getsuitastext

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

End of function getvalueastext

Function gethtml:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/Y4kOF
function name:  getHtml
number of ops:  24
compiled vars:  !0 = $id, !1 = $html
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV_INIT                                        !0      null
   80     1        CONCAT                                           ~2      '%3Cdiv+id%3D%22', !0
          2        CONCAT                                           ~3      ~2, '%22+class%3D%22playing-card+card-'
   81     3        INIT_FCALL                                               'strtolower'
          4        INIT_METHOD_CALL                                         'getValue'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                         $5      
          8        CONCAT                                           ~6      ~3, $5
   82     9        INIT_FCALL                                               'strtolower'
         10        INIT_METHOD_CALL                                         'getSuit'
         11        DO_FCALL                                      0  $7      
         12        SEND_VAR                                                 $7
         13        DO_ICALL                                         $8      
         14        CONCAT                                           ~9      ~6, $8
         15        CONCAT                                           ~10     ~9, '+'
   80    16        ASSIGN                                                   !1, ~10
   83    17        FETCH_OBJ_R                                      ~12     'facedown'
         18        BOOL                                             ~13     ~12
         19      > JMPZ                                                     ~13, ->21
         20    >   ASSIGN_OP                                     8          !1, 'playing-card-facedown+'
   84    21    >   ASSIGN_OP                                     8          !1, '%22%3E%3C%2Fdiv%3E'
   85    22      > RETURN                                                   !1
   86    23*     > RETURN                                                   null

End of function gethtml

Function getjson:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/Y4kOF
function name:  getJson
number of ops:  39
compiled vars:  !0 = $class, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   INIT_FCALL                                               'strtolower'
          1        INIT_METHOD_CALL                                         'getValue'
          2        DO_FCALL                                      0  $2      
          3        SEND_VAR                                                 $2
          4        DO_ICALL                                         $3      
          5        CONCAT                                           ~4      'playing-card+card-', $3
          6        INIT_FCALL                                               'strtolower'
          7        INIT_METHOD_CALL                                         'getSuit'
          8        DO_FCALL                                      0  $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                         $6      
         11        CONCAT                                           ~7      ~4, $6
         12        CONCAT                                           ~8      ~7, '+'
         13        ASSIGN                                                   !0, ~8
   93    14        FETCH_OBJ_R                                      ~10     'facedown'
         15        BOOL                                             ~11     ~10
         16      > JMPZ                                                     ~11, ->18
         17    >   ASSIGN_OP                                     8          !0, 'playing-card-facedown+'
   95    18    >   INIT_METHOD_CALL                                         'getSuit'
         19        DO_FCALL                                      0  $13     
         20        INIT_ARRAY                                       ~14     $13, 'suit'
   96    21        INIT_METHOD_CALL                                         'getValue'
         22        DO_FCALL                                      0  $15     
         23        ADD_ARRAY_ELEMENT                                ~14     $15, 'value'
   97    24        INIT_METHOD_CALL                                         'getSuitAsText'
         25        DO_FCALL                                      0  $16     
         26        ADD_ARRAY_ELEMENT                                ~14     $16, 'suit_text'
   98    27        INIT_METHOD_CALL                                         'getValueAsText'
         28        DO_FCALL                                      0  $17     
         29        ADD_ARRAY_ELEMENT                                ~14     $17, 'value_text'
   99    30        FETCH_OBJ_R                                      ~18     'facedown'
         31        ADD_ARRAY_ELEMENT                                ~14     ~18, 'facedown'
  100    32        ADD_ARRAY_ELEMENT                                ~14     !0, 'divclass'
   94    33        ASSIGN                                                   !1, ~14
  102    34        INIT_FCALL                                               'json_encode'
         35        SEND_VAR                                                 !1
         36        DO_ICALL                                         $20     
         37      > RETURN                                                   $20
  103    38*     > RETURN                                                   null

End of function getjson

Function flipcard:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y4kOF
function name:  flipCard
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     0  E >   FETCH_OBJ_R                                      ~0      'facedown'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->6
  111     3    >   ASSIGN_OBJ                                               'facedown'
          4        OP_DATA                                                  <true>
          5      > JMP                                                      ->8
  115     6    >   ASSIGN_OBJ                                               'facedown'
          7        OP_DATA                                                  <false>
  117     8    > > RETURN                                                   null

End of function flipcard

Function flipfacedown:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y4kOF
function name:  flipFaceDown
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  123     0  E >   ASSIGN_OBJ                                               'facedown'
          1        OP_DATA                                                  <true>
  124     2      > RETURN                                                   null

End of function flipfacedown

Function flipfaceup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y4kOF
function name:  flipFaceUp
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  130     0  E >   ASSIGN_OBJ                                               'facedown'
          1        OP_DATA                                                  <false>
  131     2      > RETURN                                                   null

End of function flipfaceup

Function isfacedown:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y4kOF
function name:  isFaceDown
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  137     0  E >   FETCH_OBJ_R                                      ~0      'facedown'
          1        BOOL                                             ~1      ~0
          2      > JMPZ                                                     ~1, ->4
  139     3    > > RETURN                                                   <true>
  141     4    > > RETURN                                                   <false>
  142     5*     > RETURN                                                   null

End of function isfacedown

End of class Card.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.39 ms | 1412 KiB | 25 Q