3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Character { protected $symbol; public function __construct($symbol) { $this->symbol = $symbol; } public function display($pointSize) { echo $this->symbol." (size ".$pointSize.")"; } } class CharacterFactory { private $characters = array(); public function getCharacter($key) { if (!array_key_exists($key, $this->characters)) $this->characters[$key] = new Character($key); return $this->characters[$key]; } } $document = "Барабан"; $chars = str_split($document); $factory = new CharacterFactory(); $debug = array(); $pointSize = 0; foreach ($chars as $key) { $pointSize++; $character = $factory->getCharacter($key); $character->display($pointSize); $debug[] = $character; } var_dump($debug);
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0alpha1
� (size 1)� (size 2)� (size 3)� (size 4)� (size 5)� (size 6)� (size 7)� (size 8)� (size 9)� (size 10)� (size 11)� (size 12)� (size 13)� (size 14)array(14) { [0]=> object(Character)#2 (1) { ["symbol":protected]=> string(1) "�" } [1]=> object(Character)#3 (1) { ["symbol":protected]=> string(1) "�" } [2]=> object(Character)#2 (1) { ["symbol":protected]=> string(1) "�" } [3]=> object(Character)#4 (1) { ["symbol":protected]=> string(1) "�" } [4]=> object(Character)#5 (1) { ["symbol":protected]=> string(1) "�" } [5]=> object(Character)#6 (1) { ["symbol":protected]=> string(1) "�" } [6]=> object(Character)#2 (1) { ["symbol":protected]=> string(1) "�" } [7]=> object(Character)#4 (1) { ["symbol":protected]=> string(1) "�" } [8]=> object(Character)#2 (1) { ["symbol":protected]=> string(1) "�" } [9]=> object(Character)#7 (1) { ["symbol":protected]=> string(1) "�" } [10]=> object(Character)#2 (1) { ["symbol":protected]=> string(1) "�" } [11]=> object(Character)#4 (1) { ["symbol":protected]=> string(1) "�" } [12]=> object(Character)#2 (1) { ["symbol":protected]=> string(1) "�" } [13]=> object(Character)#8 (1) { ["symbol":protected]=> string(1) "�" } }