Your Location is: Home > Php

Fatal error: Call to a member function getWelcome() on boolean [closed]

From: Turkey View: 1520 avinash 

Question

I get

php fatal error: Call to a member function getWelcome() on boolean in /home/cloudpanel/htdocs/domain.com/app/code/core/Mage/Page/Block/Html/Welcome.php on line 43.

How to solve this error in Magento 1.7?

class Mage_Page_Block_Html_Welcome extends Mage_Core_Block_Template
{
    /**
     * Get block messsage
     *
     * @return string
     */
    protected function _toHtml()
    {
                return Mage::app()->getLayout()->getBlock('header')->getWelcome();

    }
}

Best answer

Check http://freegento.com/doc/d7/d92/class_mage___core___model___layout.html

When the block can't be found, the getBlock returns false instead of an object, and the error is thrown when you try to call getWelcome on this.

(definition of getBlock in case the link doesn't work):

{
         if (isset($this->_blocks[$name])) {
             return $this->_blocks[$name];
         } else {
             return false;
         }
     }

Add an if statement to check if the block exists before trying to operate on it.