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 git.master, git.master_jit, rfc.property-hooks
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

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
62.91 ms | 401 KiB | 8 Q