Prado\Collections\TStack::copyFrom PHP Метод

copyFrom() публичный Метод

Note, existing data in the list will be cleared first.
public copyFrom ( $data )
    public function copyFrom($data)
    {
        if (is_array($data) || $data instanceof \Traversable) {
            $this->clear();
            foreach ($data as $item) {
                $this->_d[] = $item;
                ++$this->_c;
            }
        } else {
            if ($data !== null) {
                throw new TInvalidDataTypeException('stack_data_not_iterable');
            }
        }
    }

Usage Example

Пример #1
0
 public function testCanNotCopyFromNonTraversableTypes()
 {
     $stack = new TStack();
     $data = new stdClass();
     try {
         $stack->copyFrom($data);
     } catch (TInvalidDataTypeException $e) {
         return;
     }
     self::fail('An expected TInvalidDataTypeException was not raised');
 }