Magento 1.9 – Fatal Error: Call to a Member Function Count() on a Non-Object

magento-1.9

Fatal error: Call to a member function count() on a non-object in C:\xampp2\htdocs\magento1.9\app\design\frontend\rwd\default\template\catalog\product\list.phtml on line 2

<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count(); ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif; ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last <?php endif; ?>"></li>
<!--bof free shipping--->
<?php if ($_product->getAttributeText('new_sale') == "Yes"): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('new_sale')->toHtml(); ?>
<?php endif; ?>
<!--eof freeshipping-->
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(153); ?>" width="153" height="153" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
<h2 class="product-name">
<a href="<?php echo  $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
</a>
</h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short'); ?>
<?php endif; ?>
<?php endforeach; ?>

Best Answer

To resolve this error, simply try this one

<?php $_collectionSize = $_productCollection->count(); ?>

to

<?php $_collectionSize = count($_productCollection); ?>