3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Deck{ public $cards = array(); //creates an instance of a deck of cards (works) public function __construct(){ $values =array('2','3','4','5','6','7','8','9','10','J','Q','K','A'); $suits =array('Diamond','Club','Heart','Spade'); foreach ($suits as $suit) { foreach($values as $value){ $this->cards[] = "$value of $suit's"; } } } public function numberOfDecks($number){ $cards = $this->cards; $this->number = $number; for($i = 0 ; $i < $number; $i++){ $this->cards = array_merge($this->cards, $cards); } } } $deck = new Deck();//works as expected // how many cards are intially constructed? echo "count of cards in new deck: " . count($deck->cards) . "\n<br/>\n"; // add 3 more decks of cards $deck->numberOfDecks(3);//trouble echo "count of cards after adding 3 decks: " . count($deck->cards); // $shuffled = shuffle($deck->cards);//works as expected // var_dump($deck);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h3Sv5
function name:  (null)
number of ops:  16
compiled vars:  !0 = $deck
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   NEW                                              $1      'Deck'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   36     3        FETCH_OBJ_R                                      ~4      !0, 'cards'
          4        COUNT                                            ~5      ~4
          5        CONCAT                                           ~6      'count+of+cards+in+new+deck%3A+', ~5
          6        CONCAT                                           ~7      ~6, '%0A%3Cbr%2F%3E%0A'
          7        ECHO                                                     ~7
   39     8        INIT_METHOD_CALL                                         !0, 'numberOfDecks'
          9        SEND_VAL_EX                                              3
         10        DO_FCALL                                      0          
   40    11        FETCH_OBJ_R                                      ~9      !0, 'cards'
         12        COUNT                                            ~10     ~9
         13        CONCAT                                           ~11     'count+of+cards+after+adding+3+decks%3A+', ~10
         14        ECHO                                                     ~11
   43    15      > RETURN                                                   1

Class Deck:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/h3Sv5
function name:  __construct
number of ops:  18
compiled vars:  !0 = $values, !1 = $suits, !2 = $suit, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   12     2      > FE_RESET_R                                       $6      !1, ->16
          3    > > FE_FETCH_R                                               $6, !2, ->16
   13     4    > > FE_RESET_R                                       $7      !0, ->14
          5    > > FE_FETCH_R                                               $7, !3, ->14
   14     6    >   ROPE_INIT                                     4  ~11     !3
          7        ROPE_ADD                                      1  ~11     ~11, '+of+'
          8        ROPE_ADD                                      2  ~11     ~11, !2
          9        ROPE_END                                      3  ~10     ~11, '%27s'
         10        FETCH_OBJ_W                                      $8      'cards'
         11        ASSIGN_DIM                                               $8
         12        OP_DATA                                                  ~10
   13    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $7
   12    15      > JMP                                                      ->3
         16    >   FE_FREE                                                  $6
   17    17      > RETURN                                                   null

End of function __construct

Function numberofdecks:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 7
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 7
Branch analysis from position: 17
Branch analysis from position: 7
filename:       /in/h3Sv5
function name:  numberOfDecks
number of ops:  18
compiled vars:  !0 = $number, !1 = $cards, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        FETCH_OBJ_R                                      ~3      'cards'
          2        ASSIGN                                                   !1, ~3
   23     3        ASSIGN_OBJ                                               'number'
          4        OP_DATA                                                  !0
   24     5        ASSIGN                                                   !2, 0
          6      > JMP                                                      ->15
   25     7    >   INIT_FCALL                                               'array_merge'
          8        FETCH_OBJ_R                                      ~8      'cards'
          9        SEND_VAL                                                 ~8
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $9      
         12        ASSIGN_OBJ                                               'cards'
         13        OP_DATA                                                  $9
   24    14        PRE_INC                                                  !2
         15    >   IS_SMALLER                                               !2, !0
         16      > JMPNZ                                                    ~11, ->7
   28    17    > > RETURN                                                   null

End of function numberofdecks

End of class Deck.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.84 ms | 1400 KiB | 15 Q