gpt4 book ai didi

php - 简单的PHP错误: syntax error, unfinished class declaration

转载 作者:行者123 更新时间:2023-12-03 08:02:42 24 4
gpt4 key购买 nike

我收到两个错误,但我不知道如何解决。

我在行中收到错误“语法错误,未完成的类声明”:

private $language;

我在行中收到“语法错误,意外的'public',期望为'EOF'”:
public function getCurrencies()

这是整个代码:
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;
}
}

}

最佳答案

class Driver extends Driver没有任何意义。我认为您弄错了名字之一。

同样,您不能将实际代码放在函数之外。

移动

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

__construct()函数中,并使用 $this->var代替 $var

if(in_array($currency, $this->$currencies)中,缺少结尾的 )

if(in_array($language, $this->$languages)相同

您还以错误的方式访问成员变量。您需要使用 $this->var而不是 $this->$var来访问其名称存储在 $var中的成员变量。

关于php - 简单的PHP错误: syntax error, unfinished class declaration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5926945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com