Autor Zpráva
Fasut1
Profil *
namespace System\Collections;

class Collection extends \ArrayObject
{
    private $itemType = null;
    function setItemType($value) { $this->itemType = $value; }
    function getItemType() { return $this->itemType; }

    function offsetSet($index, $newval)
    {
        if (is_null($this->itemType)) parent::offsetSet($index, $newval);
        else
        {
            if ($newval instanceof $this->itemType) parent::offsetSet($index, $newval);
            else throw new InvalidTypeException;
        }
    }
}

class InvalidTypeException extends \Exception
{
}

Ahoj potreboval by som vytvorit kolekciu do ktorej sa budu dat vlozit len parametre urciteho typu (nieco ako genercke kolekcie) mam to spravne?

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0