Raj Malhotra
Raj Malhotra

Reputation: 55

parse error in the following php code

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;
  }
}

Upvotes: 0

Views: 57

Answers (1)

Funk Forty Niner
Funk Forty Niner

Reputation: 74217

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.

Upvotes: 1

Related Questions