- var_dump: documentation ( source)
- str_split: documentation ( source)
<?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);