Collections\Collection::add PHP Method

add() public method

public add ( $item )
    public function add($item)
    {
        $this->validateItem($item, $this->type);
        $items = $this->items;
        $items[] = $item;
        $col = new static($this->type);
        $col->setItemsFromTrustedSource($items);
        return $col;
    }

Usage Example

Example #1
0
 /**
  * @expectedException Collections\Exceptions\InvalidArgumentException
  */
 public function test_adding_wrong_class_triggers_error()
 {
     $col = new Collection('TestClassA');
     $col->add(new TestClassB());
 }