<?php

class CharacterFactory
{
    private static $instance;

    private $Characters = [];

    public static function getInstance()
    {
        if (empty(self::$instance)) {
            self::$instance = new CharacterFactory();
        }
        return self::$instance;
    }

    public function addCharacter($char)
    {
        if (!array_key_exists($char, $this->Characters)) {
            $this->Characters[$char] = new Character($char);
        }
    }

    public function getCharacters()
    {
        return $this->Characters;
    }

    public final function __clone()
    {
        throw new \Exception('This Instance is Not Clone');
    }

    public final function __wakeup()
    {
        throw new \Exception('This Instance is Not unserialize');
    }

}


class Character
{
    private $id;
    private $character;

    public function __construct($character)
    {
        $this->id = hash('sha256', time());
        $this->character = $character;
    }

    public function getId()
    {
        return $this->id;
    }

    public function getCharacter()
    {
        return $this->character;
    }
}


$chars = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
    'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
    'Y', 'Z'
];

$factory = CharacterFactory::getInstance();

for ($i=0; $i<20; $i++) 
{
    $select_char = $chars[rand(0, 25)];
    echo sprintf('%s / ', $select_char);
    $factory->addCharacter($select_char);
}

echo '<hr>';

foreach ($factory->getCharacters() as $char_data) 
{
    echo sprintf('%s<br>', $char_data->getCharacter());
}