I have created a custom block and when I try to access a method from my block I get:

exception 'Exception' with message 'Notice: Undefined variable: this­ in /Applications/XAMPP/xamppfiles/htdocs/mag19/app/design/frontend/vish/default/template/Vish/sizecheck/sizecheck.phtml on line 2' in /Applications/XAMPP/xamppfiles/htdocs/mag19/app/code/core/Mage/Core/functions.php:232

My sizecheck.phtml:

$products = $this­->igetText();

<div id="product_list">
  <?php echo($products);?>

The block:

class Vish_SizeCheck_Block_Size extends Mage_Core_Block_Template {
      public function igetText()
        return "I am inside `" . get_class(). "` block and it is my first custom block ever !";


    <?xml version="1.0"?>

my sizecheck.xml:

    <?xml version="1.0"?>
<layout version="0.1.0">
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
        <reference name="content">
            <block type="core/template" name="sizecheck.form" as="sizecheck_form" template="Vish/sizecheck/form.phtml"/>

My block declaration in CMS Page:

{{block type="vish_sizecheck/size" name="sizecheck" template="Librex/sizecheck/sizecheck.phtml"}}

I can see the class is correctly inherited by:

echo get_class($this);
  • Show your sizecheck.xml. – Sohel Rana Jul 1 '19 at 15:48
  • @SohelRana that is for the route part only but will add now – Vaishal Patel Jul 1 '19 at 15:55
  • Is it is comes in igetText()? did you try die('here') in your funciton ? – Ravi Soni Jul 1 '19 at 17:30

The solution was rather staring me in the face. Looking at the error,

'Notice: Undefined variable: this­ in...

It was not instantiating the variable $this, even though the line was set as:

  $products = $this­->igetText();

Debugging this line further it revealed there was a hidden character:

The hidden character

So, deleting this line and retyping the line got everything working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.