我遇到两个错误,我不知道如何解决这个问题。
我在第<:p>行收到错误“语法错误,未完成的类声明”
private $language;
我收到了“语法错误,意外'公开',期待'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;
}
}
}
答案 0 :(得分:6)
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
来访问{em>名称存储在$var
中的成员变量。
答案 1 :(得分:2)
你有4个错误:
固定代码:
<?php
class 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 */
public $currencies = array("USD", "CAD");
/* Allowed languages */
public $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;
}
}
}
答案 2 :(得分:1)
/*
* Set the currency
*/
function setCurrency($currency){
if(in_array($currency, $this->$currencies)
错过了结束)
,setLanguage(..)
同样class Driver extends Driver
没有任何意义,应该只是class Driver
答案 3 :(得分:1)
有一些错误:
您需要为private
和$currencies
类实例数组使用$languages
(或其他一个可见性选项)。
您的setCurrency
和setLanguage
方法缺少第一个if(in_array(
行的右括号。
另外,您是否打算使用名为driver的类扩展名为driver的类? (我非常怀疑你只想使用class Driver {
。)