duanqian9503 2011-05-08 10:42
浏览 31
已采纳

简单的PHP错误:语法错误,未完成的类声明

I get two errors and I dont know how to fix this.

I get the error "syntax error, unfinished class declaration" at the line:

private $language;

I get "syntax error, unexpected 'public', expecting 'EOF'" at the line:

public function getCurrencies()

This is the whole code:

class Driver extends Driver{

public static $url = "http://www.com/";
/* The method of posting data to the website */
public static $method = "GET";
/* The part of the url extending the domain name until the search term */
public static $url_searchbase = "search/searchresults.aspx?N=0&Ntt=";
/* The part of the url entailing the search term, deifining additional paramters */
public static $url_searchtail = "&Ntk=Primary&i=0&sw=n&ps=9999&pn=1";
private $currency;
private $language;
/* Allowed currencies */
$currencies = array("USD", "CAD");
/* Allowed languages */
$languages = array("ENU");

function __construct($currency, $language){
    if(setCurrency($currency) AND setLanguage($language)){
        return TRUE;
    } else {
        trigger_error("Currency '". $currency ."' or Language '". $language ."' not supported.", E_USER_ERROR);
        return FALSE;
    }
}

/*
 * Return an array of allowed currencies
 */
public function getCurrencies(){
    return $currencies;
}

/*
 * Set the currency
 */
function setCurrency($currency){
    if(in_array($currency, $this->$currencies)
    {
        $this->$currency = $currency;
        return TRUE;
    } else {
        trigger_error("Currency '". $currency ."' not supported.", E_USER_ERROR);
        return FALSE;
    }
}

/*
 * Return an array of allowed languages
 */
public function getLanguages(){
    return $languages;
}

/*
 * Set the language
 */
public function setLanguage($language){
        if(in_array($language, $this->$languages)
    {
        $this->$language = $language;
        return TRUE;
    } else {
        trigger_error("Language '". $language ."' not supported.", E_USER_ERROR);
        return FALSE;
    }
}

}
  • 写回答

4条回答 默认 最新

  • doufuhao0566 2011-05-08 10:46
    关注

    class Driver extends Driver makes no sense. I think you got one of the names wrong.

    Also, you cannot put real code outside of a function.

    Move

    /* Allowed currencies */
    $currencies = array("USD", "CAD");
    /* Allowed languages */
    $languages = array("ENU");
    

    into your __construct() function and use $this->var instead of $var.

    In if(in_array($currency, $this->$currencies) there's missing a closing ).

    Same for if(in_array($language, $this->$languages)

    You are also accessing the member vars in an incorrect way. You need to use $this->var instead of $this->$var which would access the member variable whose name is stored in $var.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探