When I use “echo” in vendor methods – products not showing, but work fine without it

I got the next code:

public function getProductCollection() {     if (isset($  this->_productCollections[$  this->getCurrentCategory()->getId()])) {         $  collection = $  this->_productCollections[$  this->getCurrentCategory()->getId()];     } else {         $  collection = $  this->collectionProvider->getCollection($  this->getCurrentCategory());         $  this->prepareProductCollection($  collection);         $  this->_productCollections[$  this->getCurrentCategory()->getId()] = $  collection;     }     echo "Collection count".$  collection->count();     return $  collection; } 

When I tried to echo collection count – it always equals 0, but when I delete this string – everything is okay count equals 16. How?