public
    function add(
        $value = null,
        $key = ''
    ) {
        //var_dump($this->type);
        //var_dump($value);
        //var_dump(is_object($value));
        //die;

        if ($this->isClass) {
            //echo "  isClass".PHP_EOL;
            if (!is_a($value, $this->type)) {
                //throw new TypeCheckException('Object type "'.get_class($value).'" is not of type "'.$this->type.'".');
                $type = is_object($value) ? get_class($value) : gettype($value);
                throw new TypeCheckException('Object type "'.$type.'" is not of type "'.$this->type.'".');
            } else {
                // add to collection
                if ($key != '') {
                    if (array_key_exists($key, $this->collection)) {
                        throw new ArgumentException(
                            'Can not add object to key "'.$key.'", because key already exists.'
                        );
                    } else {
                        $this->collection[$key] = $value;
                    }
                } else {
                    array_push($this->collection, $value);
                }
            }
        } else {
            //echo "  noClass".PHP_EOL;
            if ($this->type == gettype($value)) {
                // add to collection
                if ($key != '') {
                    if (array_key_exists($key, $this->collection)) {
                        throw new ArgumentException('Can not add value to key "'.$key.'", because key already exists.');
                    } else {
                        $this->collection[$key] = $value;
                    }
                } else {
                    array_push($this->collection, $value);
                }
            } else {
                throw new TypeCheckException('Value type "'.gettype($value).'" is not of type "'.$this->type.'".');
            }
        }
    }
public
    function add(
        $value = null,
        $key = ''
    ) {
        //var_dump($this->type);
        //var_dump($value);
        //var_dump(is_object($value));
        //die;

        if ($this->isClass) {
            //echo "  isClass".PHP_EOL;
            if (!is_a($value, $this->type)) {
                //throw new TypeCheckException('Object type "'.get_class($value).'" is not of type "'.$this->type.'".');
                $type = is_object($value) ? get_class($value) : gettype($value);
                throw new TypeCheckException('Object type "'.$type.'" is not of type "'.$this->type.'".');
            } else {
                // add to collection
                if ($key != '') {
                    if (array_key_exists($key, $this->collection)) {
                        throw new ArgumentException(
                            'Can not add object to key "'.$key.'", because key already exists.'
                        );
                    } else {
                        $this->collection[$key] = $value;
                    }
                } else {
                    array_push($this->collection, $value);
                }
            }
        } else {
            //echo "  noClass".PHP_EOL;
            if ($this->type == gettype($value)) {
                // add to collection
                if ($key != '') {
                    if (array_key_exists($key, $this->collection)) {
                        throw new ArgumentException('Can not add value to key "'.$key.'", because key already exists.');
                    } else {
                        $this->collection[$key] = $value;
                    }
                } else {
                    array_push($this->collection, $value);
                }
            } else {
                throw new TypeCheckException('Value type "'.gettype($value).'" is not of type "'.$this->type.'".');
            }
        }
    }
public function add ( $ value = null , $ key = '' ) { //var_dump($this->type); //var_dump($value); //var_dump(is_object($value)); //die; if ( $ this -> isClass ) { //echo "  isClass".PHP_EOL; if ( ! is_a ( $ value , $ this -> type ) ) { //throw new TypeCheckException('Object type "'.get_class($value).'" is not of type "'.$this->type.'".'); $ type = is_object ( $ value ) ? get_class ( $ value ) : gettype ( $ value ) ; throw new TypeCheckException ( 'Object type "' . $ type . '" is not of type "' . $ this -> type . '".' ) ; } else { // add to collection if ( $ key != '' ) { if ( array_key_exists ( $ key , $ this -> collection ) ) { throw new ArgumentException ( 'Can not add object to key "' . $ key . '", because key already exists.' ) ; } else { $ this -> collection [ $ key ] = $ value ; } } else { array_push ( $ this -> collection , $ value ) ; } } } else { //echo "  noClass".PHP_EOL; if ( $ this -> type == gettype ( $ value ) ) { // add to collection if ( $ key != '' ) { if ( array_key_exists ( $ key , $ this -> collection ) ) { throw new ArgumentException ( 'Can not add value to key "' . $ key . '", because key already exists.' ) ; } else { $ this -> collection [ $ key ] = $ value ; } } else { array_push ( $ this -> collection , $ value ) ; } } else { throw new TypeCheckException ( 'Value type "' . gettype ( $ value ) . '" is not of type "' . $ this -> type . '".' ) ; } } }
Add value to collection.

@param mixed  $value
@param string $key

@throws TypeCheckException
@throws ArgumentException
Add value to collection .