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);
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
count of cards in new deck: 52 <br/> Deprecated: Creation of dynamic property Deck::$number is deprecated in /in/h3Sv5 on line 23 count of cards after adding 3 decks: 208
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 count of cards in new deck: 52 <br/> Deprecated: Creation of dynamic property Deck::$number is deprecated in /in/h3Sv5 on line 23 count of cards after adding 3 decks: 208
Output for 5.6.0 - 5.6.38, 7.0.0 - 7.0.31, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
count of cards in new deck: 52 <br/> count of cards after adding 3 decks: 208

preferences:
202.65 ms | 403 KiB | 282 Q