0

while using the below code i am getting error like this Parse error: in C:\wamp\www\magento3\app\code\local\Envato\Recentproducts\Block\Recentproducts.php on line 7

<?php
// app/code/local/Envato/Recentproducts/Block/Recentproducts.php
class Envato_Recentproducts_Block_Recentproducts extends Mage_Core_Block_Template {
  public function getRecentProducts() {
    // call model to fetch data
    $arr_products = array();
    $products = Mage::getModel("recentproducts/recentproducts")­>getRecentProducts();

    foreach ($products as $product) {
      $arr_products[] = array(
        'id' => $product->getId(),
        'name' => $product­>getName(),
        'url' => $product­>getProductUrl(),
      );
    }

    return $arr_products;
  }
}
10
  • 1
    Look really close at that line. Character by character. Commented Aug 20, 2015 at 13:32
  • Double check your code. It looks like you've some unicode happening here or some unrecognizable characters. Commented Aug 20, 2015 at 13:41
  • which editor are you using to code with? Commented Aug 20, 2015 at 13:43
  • You have > instead of -> before getRecentProducts() Commented Aug 20, 2015 at 13:52
  • 1
    @TimLewis Bizarre... lordie, you're telling me. Twilight Zone stuff. Commented Aug 20, 2015 at 13:59

1 Answer 1

1

There appears to be some type of hyphens that looks like a regular - but isn't.

I tried to figure out which character that is, but was unable to.

I have replaced all of those with my keyboard -.

Sidenote: Something rather strange is happening here. Your code is not showing the missing hyphens, but when I copy/pasted it, they appeared in my editor.

If you go into Stack's "edit mode" for it see for yourself-as per original post, the hyphens are there.

  • Can someone explain this? I couldn't figure it out. (Twilight Zone).

Here is a rewrite, this should work.

Important: (Copy/paste the code below, do not edit your existing code)

<?php
// app/code/local/Envato/Recentproducts/Block/Recentproducts.php
class Envato_Recentproducts_Block_Recentproducts extends Mage_Core_Block_Template {
  public function getRecentProducts() {
    // call model to fetch data
    $arr_products = array();
    $products = Mage::getModel("recentproducts/recentproducts")->getRecentProducts();

    foreach ($products as $product) {
      $arr_products[] = array(
        'id' => $product->getId(),
        'name' => $product->getName(),
        'url' => $product->getProductUrl(),
      );
    }

    return $arr_products;
  }
}

Another strange thing; hyphens are not showing in edit mode and show up as

$product>getName
$product>getProductUrl()

but when copied/pasted, they show up as:

$product->getName
$product->getProductUrl()
  • TBH, I for one am totally baffled.
  • If anyone has an explanation, please feel free to edit and/or comment.
  • OP used Notepad++ as their code editor.
Sign up to request clarification or add additional context in comments.

2 Comments

got it i just removed those hyphens and placed it again from my keyboard.now it is working fine.thanks...
@RajMalhotra You're welcome Raj, I'm glad we were able to work this out, cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.