Parse error: syntax error, unexpected '$result' (T_VARIABLE), expecting function (T_FUNCTION) : <p>we are trying to rewrite core shipping model in magento.we are trying following code : but we are getting error as follows : </p>

<p>we removed the line that we are getting error</p>

<p>but still the problem didt resolved.</p>

<pre><code> we are getting this error : Parse error: syntax error, 

unexpected '$result' (T_VARIABLE), expecting function (T_FUNCTION) in 

    /app/code/local/Webkul/Mpperproductshipping/Model/Shipping.php on line 56
</code></pre>

<p>we are using following code, you can see error at the end of the line.</p>

<pre><code>&lt;?php
class Webkul_Mpperproductshipping_Model_Carrier_LocalDelivery extends Mage_Shipping_Model_Carrier_Abstract
{
    /*  Use group alias */
    protected $_code = 'mpperproductshipping';


    // Prateek code start

   public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
    $storeId = $request-&gt;getStoreId();
    if (!$request-&gt;getOrig()) {
        $request
            -&gt;setCountryId(Mage::getStoreConfig(self::XML_PATH_STORE_COUNTRY_ID, $request-&gt;getStore()))
            -&gt;setRegionId(Mage::getStoreConfig(self::XML_PATH_STORE_REGION_ID, $request-&gt;getStore()))
            -&gt;setCity(Mage::getStoreConfig(self::XML_PATH_STORE_CITY, $request-&gt;getStore()))
            -&gt;setPostcode(Mage::getStoreConfig(self::XML_PATH_STORE_ZIP, $request-&gt;getStore()));
    }

    $postCode = $request-&gt;getDestPostcode();
    $restrictedCodes = array(
        110001,
        110002
        );
    //restricted values. they can come from anywhere

    if (!in_array($postCode, $restrictedCodes)) {
        return $this;
    }

    $limitCarrier = $request-&gt;getLimitCarrier();
    if (!$limitCarrier) {
        $carriers = Mage::getStoreConfig('carriers', $storeId);

        foreach ($carriers as $carrierCode =&gt; $carrierConfig) {
            $this-&gt;collectCarrierRates($carrierCode, $request);
        }
    } else {
        if (!is_array($limitCarrier)) {
            $limitCarrier = array($limitCarrier);
        }
        foreach ($limitCarrier as $carrierCode) {
            $carrierConfig = Mage::getStoreConfig('carriers/' . $carrierCode, $storeId);
            if (!$carrierConfig) {
                continue;
            }
            $this-&gt;collectCarrierRates($carrierCode, $request);
        }
    }

    return $this;
}

   // Prateek code  end 

     //   $result = Mage::getModel('shipping/rate_result');

        /* Edited by vikas_mageworx */
        $postcode=$request-&gt;getDestPostcode();
        $countrycode=$request-&gt;getDestCountry();
        $items=$request-&gt;getAllItems();
        /* End Editing by vikas_mageworx */

        $postcode=str_replace('-', '', $postcode);
        $shippingdetail=array();

        /*  one start */
        $shippostaldetail=array('countrycode'=&gt;$countrycode,'postalcode'=&gt;$postcode,'items'=&gt;$items);
       /*  one end  */



        foreach($items as $item) {
            $proid=$item-&gt;getProductId();
            $options=$item-&gt;getProductOptions();
            $mpassignproductId=$options['info_buyRequest']['mpassignproduct_id'];
            if(!$mpassignproductId) {
                foreach($item-&gt;getOptions() as $option) {
                    $temp=unserialize($option['value']);
                    if($temp['mpassignproduct_id']) {
                        $mpassignproductId=$temp['mpassignproduct_id'];
                    }
                }
            }
            if($mpassignproductId) {
                $mpassignModel = Mage::getModel('mpassignproduct/mpassignproduct')-&gt;load($mpassignproductId);
                $partner = $mpassignModel-&gt;getSellerId();
            } else {
                $collection=Mage::getModel('marketplace/product')
                    -&gt;getCollection()-&gt;addFieldToFilter('mageproductid',array('eq'=&gt;$proid));
                foreach($collection as $temp) {
                    $partner=$temp-&gt;getUserid();
                }
            }

            $product=Mage::getModel('catalog/product')-&gt;load($proid)-&gt;getWeight();
            $weight=$product*$item-&gt;getQty();
            if(count($shippingdetail)==0){
                array_push($shippingdetail,array('seller_id'=&gt;$partner,'items_weight'=&gt;$weight,'product_name'=&gt;$item-&gt;getName(),'qty'=&gt;$item-&gt;getQty(),'item_id'=&gt;$item-&gt;getId()));
            }else{
                $shipinfoflag=true;
                $index=0;
                foreach($shippingdetail as $itemship){
                    if($itemship['seller_id']==$partner){
                        $itemship['items_weight']=$itemship['items_weight']+$weight;
                        $itemship['product_name']=$itemship['product_name'].",".$item-&gt;getName();
                        $itemship['item_id']=$itemship['item_id'].",".$item-&gt;getId();
                        $itemship['qty']=$itemship['qty']+$item-&gt;getQty();
                        $shippingdetail[$index]=$itemship;
                        $shipinfoflag=false;
                    }
                    $index++;
                }
                if($shipinfoflag==true){
                    array_push($shippingdetail,array('seller_id'=&gt;$partner,'items_weight'=&gt;$weight,'product_name'=&gt;$item-&gt;getName(),'qty'=&gt;$item-&gt;getQty(),'item_id'=&gt;$item-&gt;getId()));
                }
            }
        }
        $shippingpricedetail=$this-&gt;getShippingPricedetail($shippingdetail,$shippostaldetail);

        if($shippingpricedetail['errormsg']!==""){
            Mage::getSingleton('core/session')-&gt;setShippingCustomError($shippingpricedetail['errormsg']);
            return $result;
        }
        /*store shipping in session*/
        $shippingAll=Mage::getSingleton('core/session')-&gt;getData('shippinginfo');
        $shippingAll[$this-&gt;_code]=$shippingpricedetail['shippinginfo'];
        Mage::getSingleton('core/session')-&gt;setData('shippinginfo',$shippingAll);

        $method = Mage::getModel('shipping/rate_result_method');
        $method-&gt;setCarrier($this-&gt;_code);
        $method-&gt;setCarrierTitle(Mage::getStoreConfig('carriers/'.$this-&gt;_code.'/title'));
        /* Use method name */
        $method-&gt;setMethod($this-&gt;_code);
        $method-&gt;setMethodTitle(Mage::getStoreConfig('carriers/'.$this-&gt;_code.'/name'));
        $method-&gt;setCost($shippingpricedetail['handlingfee']);
        $method-&gt;setPrice($shippingpricedetail['handlingfee']); 
        $result-&gt;append($method);
        return $result; 
    }

public function getShippingPricedetail($shippingdetail,$shippostaldetail) {
        $shippinginfo=array();
        $handling=0;
        $session = Mage::getSingleton('checkout/session');
        $customerAddress = $session-&gt;getQuote()-&gt;getShippingAddress();


/* Edited by vikas_boy */
$customerPostCode = $shippostaldetail['postalcode'];
$items = $shippostaldetail['items'];
 /* End Editing by vikas_boy  */


 /* one  */

        foreach($shippingdetail as $shipdetail) {
            $seller = Mage::getModel("customer/customer")-&gt;load($shipdetail['seller_id']);
            $sellerAddress = $seller-&gt;getPrimaryShippingAddress();
            $distance = $this-&gt;getDistanse($sellerAddress-&gt;getPostcode(),$customerPostCode);
            // echo "distance ".$distance;die;
            $price = 0;
            $itemsarray=explode(',',$shipdetail['item_id']);
            foreach($items as $item) {
                $proid=$item-&gt;getProductId();
                $options=$item-&gt;getProductOptions();
                $mpassignproductId=$options['info_buyRequest']['mpassignproduct_id'];
                if(!$mpassignproductId) {
                    foreach($item-&gt;getOptions() as $option) {
                        $temp=unserialize($option['value']);
                        if($temp['mpassignproduct_id']) {
                            $mpassignproductId=$temp['mpassignproduct_id'];
                        }
                    }
                }
                if (Mage::getModel('catalog/product_type_configurable')-&gt;getParentIdsByChild($proid))
                {
                    continue;
                }
                $mpshippingcharge = 0;
                $localDistance = Mage::getStoreConfig('marketplace/mpperproductshipping/local_shipping_distance');
                $regionalDistance = Mage::getStoreConfig('marketplace/mpperproductshipping/regional_shipping_distance');
                $stateDistance = Mage::getStoreConfig('marketplace/mpperproductshipping/state_shipping_distance');
                if(in_array($item-&gt;getId(),$itemsarray)) {
                    if($mpassignproductId) {
                        if($distance &lt; $localDistance) {
                            $mpshippingcharge=Mage::getModel('mpassignproduct/mpassignproduct')-&gt;load($mpassignproductId)-&gt;getLocalShippingCharge();
                        } elseif($distance &gt; $localDistance &amp;&amp; $distance &lt; $regionalDistance) {
                            $mpshippingcharge=Mage::getModel('mpassignproduct/mpassignproduct')-&gt;load($mpassignproductId)-&gt;getRegionalShippingCharge();
                        } elseif($distance &gt; $regionalDistance) {
                            $mpshippingcharge=Mage::getModel('mpassignproduct/mpassignproduct')-&gt;load($mpassignproductId)-&gt;getStateShippingCharge();
                        }
                    } else {
                         // echo "imte ".$item-&gt;getProductId();
                        if($distance &lt; $localDistance) {
                            $mpshippingcharge=Mage::getModel('catalog/product')-&gt;load($item-&gt;getProductId())-&gt;getMpLocalShippingCharge();
                            // echo "imte ".$item-&gt;getProductId();
                            // echo "ship ".$mpshippingcharge;
                        } elseif($distance &gt; $localDistance &amp;&amp; $distance &lt; $regionalDistance) {
                            $mpshippingcharge=Mage::getModel('catalog/product')-&gt;load($item-&gt;getProductId())-&gt;getMpRegionalShippingCharge();
                        } elseif($distance &gt; $regionalDistance) {
                            $mpshippingcharge=Mage::getModel('catalog/product')-&gt;load($item-&gt;getProductId())-&gt;getMpStateShippingCharge();
                        }   
                    }

                    /* tt */
                    // echo "test ".$mpshippingcharge;die;
                    if(!is_numeric($mpshippingcharge)){
                        $price=$price+floatval($this-&gt;getConfigData('defalt_ship_amount')* floatval($item-&gt;getQty()));
                    }else{
                        $price=$price+($mpshippingcharge * floatval($item-&gt;getQty()));
                    }

                }
            }

            $handling = $handling+$price;
            $submethod = array(array('method'=&gt;Mage::getStoreConfig('carriers/'.$this-&gt;_code.'/title'),'cost'=&gt;$price,'error'=&gt;0));
            array_push($shippinginfo,array('seller_id'=&gt;$shipdetail['seller_id'],'methodcode'=&gt;$this-&gt;_code,'shipping_ammount'=&gt;$price,'product_name'=&gt;$shipdetail['product_name'],'submethod'=&gt;$submethod,'item_ids'=&gt;$shipdetail['item_id']));
        }
        $msg="";
        return array('handlingfee'=&gt;$handling,'shippinginfo'=&gt;$shippinginfo,'errormsg'=&gt;$msg);
    }


 /* one end */

    /* tt start */

    private function getDistanse($origin,$destination) {
        $url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=".$origin.",india&amp;destinations=".$destination.",india&amp;mode=driving&amp;language=en-EN&amp;sensor=false";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $response = curl_exec($ch);
        curl_close($ch);
        $response_all = json_decode($response);
        $distance = $response_all-&gt;rows[0]-&gt;elements[0]-&gt;distance-&gt;value / 1000;
        if($distance==0){
            $zips = array(
                $origin,$destination
                // ... etc ...
            );

            $geocoded = array();
            $serviceUrl = "http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:%s&amp;sensor=false";
            $curl = curl_init();
            foreach ($zips as $zip) {
                curl_setopt($curl, CURLOPT_URL, sprintf($serviceUrl, urlencode($zip)));
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
                $data = json_decode(curl_exec($curl));
                $info = curl_getinfo($curl);
                if ($info['http_code'] != 200) {
                    // Request failed
                } else if ($data-&gt;status !== 'OK') {
                    // Something happened, or there are no results
                } else {
                    $geocoded[$zip] =$data-&gt;results[0]-&gt;geometry-&gt;location;
                }
            }
            $distance=$this-&gt;DistAB($geocoded[$zips[0]]-&gt;lat,$geocoded[$zips[0]]-&gt;lng,$geocoded[$zips[1]]-&gt;lat,$geocoded[$zips[1]]-&gt;lng);

            }
        return $distance;
    }


public function DistAB($lat_a,$lon_a,$lat_b,$lon_b)

      { 

        $measure_unit = 'kilometers';

        $measure_state = false;

        $measure = 0;

        $error = '';

          $delta_lat = $lat_b - $lat_a ;
          $delta_lon = $lon_b - $lon_a ;
          $earth_radius = 6372.795477598;

          $alpha    = $delta_lat/2;
          $beta     = $delta_lon/2;
          $a        = sin(deg2rad($alpha)) * sin(deg2rad($alpha)) + cos(deg2rad($this-&gt;lat_a)) * cos(deg2rad($this-&gt;lat_b)) * sin(deg2rad($beta)) * sin(deg2rad($beta)) ;
          $c        = asin(min(1, sqrt($a)));
          $distance = 2*$earth_radius * $c;
          $distance = round($distance, 4);

         $measure = $distance;
         return $measure;

      }

    }

 /*  tt end */
</code></pre>
