Weird "Call to a member function title() on string" error

I am running in the following error.

I have a collection of objects which I am displaying in a grid.

When this collection of objects (pages) is larger then 1, everything is fine (ex http://memoriestoriche.it/en/categories/other/altro). When the collection is just 1, PHP returns me the following error if I try to echo $item->title()

Call to a member function title() on string

If I var_dump the first item in the collection of more then 1, this is what I get:

object(Page)[364]
 public 'title' => string 'marche_macerata_impiegati-e-assenteismo_antico-manifesto_inusuale_rarita_1849' (length=77)
 public 'id' => string 'collezione/M/marche-macerata-impiegati-e-assenteismo-antico-manifesto-inusuale-rarita-1849' (length=90)
 public 'uid' => string 'marche-macerata-impiegati-e-assenteismo-antico-manifesto-inusuale-rarita-1849' (length=77)
 public 'slug' => string 'marche-macerata-impiegati-e-assenteismo-antico-manifesto-inusuale-rarita-1849' (length=77)

If I var_dump the first item in the collection of just one (which returns the error), I get a similar object:

object(Page)[524]
  public 'title' => string 'interessante-tavolino-depoca_smontabile_originale' (length=49)
  public 'id' => string 'collezione/I/interessante-tavolino-depoca-smontabile-originale' (length=62)
  public 'uid' => string 'interessante-tavolino-depoca-smontabile-originale' (length=49)
  public 'slug' => string 'interessante-tavolino-depoca-smontabile-originale' (length=49)

How come, even if both are object(Page), I can access one $item->title(), but not the other one?

Could you post your code please?

Actually I understood what the problem was while I was copying and pasting my code here.

I had several arrays of uri, from which I was finding my collection of pages for each category.

$collection = $site->find($collection);

Whenever a category had only 1 object, $site->find() would return a single page, rather then a collection of object, so it was throwing error when I iterated with foreach.

I resolved by having an if statement before rendering the grid of item, which checks:

<?php if (count($collection) > 1): ?>
    <?php foreach ($collection as $item): ?>
      <?php snippet('item', array('item', $item)) ?>
    <?php endforeach ?>
<?php else: ?>
    <?php $item = $collection ?>
    <?php snippet('item', array('item' => $item)) ?>
<?php endif ?>

Thank you anyway for letting me stumble onto it!