Dom*_*nik 1 php oop syntax-error
我得到两个错误,我不知道如何解决这个问题.
我在行处收到错误"语法错误,未完成的类声明":
private $language;
Run Code Online (Sandbox Code Playgroud)
我得到"语法错误,意外'公开',期待'EOF'"在这一行:
public function getCurrencies()
Run Code Online (Sandbox Code Playgroud)
这是整个代码:
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
class Driver extends Driver没有意义.我觉得你有一个错误的名字.
此外,您不能将实际代码放在函数之外.
移动
/* Allowed currencies */
$currencies = array("USD", "CAD");
/* Allowed languages */
$languages = array("ENU");
Run Code Online (Sandbox Code Playgroud)
进入你的__construct()功能而$this->var不是使用$var.
在if(in_array($currency, $this->$currencies)那里错过了一个结束).
同样的 if(in_array($language, $this->$languages)
您也以不正确的方式访问成员变量.您需要使用$this->var而不是使用$this->$var哪个将访问其名称存储在其中的成员变量$var.