dongyukui8330 2016-04-27 21:35
浏览 40
已采纳

“<br /> <b>解析错误</ b>:语法错误,<b> /home/site/public_html/devel/modules//filter.php </ b>中的意外”{“行<b> 35 </ b> <br />“

I'm facing a really weird issues with a scripts which worked 2 weeks ago and now is throwing the following error:

"<br /> <b>Parse error</b>: syntax error, unexpected '{' in <b>/home/site/public_html/devel/modules/filter.php</b> on line <b>35</b><br /> "

This is the code and I've had a look thousand of times but I can't figure out what's wrong in it ...

   <?php

define('_JEXEC',1); 
define('JPATH_BASE', realpath(dirname(__FILE__).'/../..' ));

require_once(JPATH_BASE.'/includes/defines.php');
require_once(JPATH_BASE.'/includes/framework.php');
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
$db = JFactory::getDBO();

ob_start();
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');


  function getCountries() {
     try {
       $db = JFactory::getDBO();
       $query = "SELECT id, name FROM `#__countries`";
       $db->setQuery($query);
       $result =  $db->loadRowList();
       if(!$result) {
         throw new exception("Country not found.");
       }
       $res = array();
          foreach($result as $key=>$value) {
        $res[$value[0]] = $value[1];
       }
       $data = array('status'=>'success', 'tp'=>1, 'msg'=>"Countries fetched successfully.", 'result'=>$res);
     }
     catch (Exception $e) {
       $data = array('status'=>'error', 'tp'=>0, 'msg'=>$e->getMessage());
     } 
     finally {
        return $data;
     }
   }

  // Fetch all states list by country id
  function getStates($countryId) {
     try {
       $db = JFactory::getDBO();
       $query = "SELECT id, name FROM #__states WHERE country_id=".$countryId;
       $db->setQuery($query);
       $result =  $db->loadRowList();
       if(!$result) {
         throw new exception("State not found.");
       }
       $res = array();
         foreach($result as $key=>$value) {
        $res[$value[0]] = $value[1];
       }
       $data = array('status'=>'success', 'tp'=>1, 'msg'=>"States fetched successfully.", 'result'=>$res);
     } catch (Exception $e) {
       $data = array('status'=>'error', 'tp'=>0, 'msg'=>$e->getMessage());
     } finally {
        return $data;
     }
   }

 // Fetch all cities list by state id
  function getCities($stateId) {
     try {
       $db = JFactory::getDBO();
       $query = "SELECT id, name FROM #__cities WHERE state_id=".$stateId;
       $db->setQuery($query);
       $result =  $db->loadRowList();
       if(!$result) {
         throw new exception("City not found.");
       }
       $res = array();
         foreach($result as $key=>$value) {
        $res[$value[0]] = $value[1];
       }
       $data = array('status'=>'success', 'tp'=>1, 'msg'=>"Cities fetched successfully.", 'result'=>$res);
     } catch (Exception $e) {
       $data = array('status'=>'error', 'tp'=>0, 'msg'=>$e->getMessage());
     } finally {return $data;}}   

try {
  if(!isset($_GET['type']) || empty($_GET['type'])) {
    throw new exception("Type is not set.");
  }
  $type = $_GET['type'];
  if($type=='getCountries') {
    $data = getCountries();
  } 

  if($type=='getStates') {
     if(!isset($_GET['countryId']) || empty($_GET['countryId'])) {
        throw new exception("Country Id is not set.");
     }
     $countryId = $_GET['countryId'];
     $data = getStates($countryId);
  }

   if($type=='getCities') {
     if(!isset($_GET['stateId']) || empty($_GET['stateId'])) {
        throw new exception("State Id is not set.");
     }
     $stateId = $_GET['stateId'];
     $data = getCities($stateId);
  }

} catch (Exception $e) {
   $data = array('status'=>'error', 'tp'=>0, 'msg'=>$e->getMessage());
} finally {
  echo json_encode($data);
}

ob_flush();
?>

Can someone tell me what's wrong ?

  • 写回答

1条回答 默认 最新

  • dqg2269 2016-04-27 21:50
    关注

    That parses fine on PHP 5.6. Line 35 is the finally keyword. If your PHP version is older than 5.5 I imagine you would get a parse error here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来