2016-04-27 3 views
1

Je suis face à un problèmes vraiment bizarre avec des scripts qui ont travaillé il y a 2 semaines et est maintenant jeter l'erreur suivante:"<br /><b>Parse error</b>: erreur de syntaxe, unexpected '{' dans <b>/home/site/public_html/devel/modules//filter.php</b> en ligne <br />"

"<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 /> " 

Voici le code et j'ai regardé des milliers de fois, mais je ne peux pas comprendre ce qui ne va pas dans ce ..

<?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(); 
?> 
Quelqu'un peut me dire ce qui ne va pas?

+3

Quelle version de PHP? 'finally' nécessite PHP> = 5.5 –

+0

PHP Version actuellement installée est 5.4.5. Merci l'homme, je n'étais pas au courant que cela pourrait être causé par la version de PHP – Mastermind

Répondre

1

Cela fonctionne bien sur PHP 5.6. La ligne 35 est le mot-clé finally. Si votre version de PHP est antérieure à 5.5, j'imagine que vous obtiendrez une erreur d'analyse ici.