0
我得到這個錯誤,當我運行該腳本PHP的致命錯誤:不能重新聲明類AppMailCore在/appmail.core.php第10行
php Fatal error: Cannot redeclare class AppMailCore in /appmail.core.php on line 10
我需要循環,也會使用一些變量從一個類文件。從main.php中的代碼看起來是這樣的:
$iesc = 1; while($iesc less than 5) { include('includes/appmail.core.php'); ---
我用「小於」在上面,因爲我不知道該反轉義代碼‘<’symbold預標記之內。
我明白,我不能重新去關注類,但我不知道如何讓類變量通過循環運行。 appmail.core.php看起來像這樣
require_once('appmail.config.php'); require_once('helpers'.DIRECTORY_SEPARATOR.'appmail.rest.php'); class AppMailCore { var $AppMailRest; var $api_key; var $url; /** * Initialises AppMailCore. Optionally provide runtime api key and url. */ function AppMailCore($api_key = APPMAIL_API_KEY, $url = APPMAIL_URL) { $this->url = $url; $this->api_key = $api_key; $this->AppMailRest = new AppMailRest($this->url); } /** * Asynchronously sends an email using Google App Engine * * Params are fairly self explanatory. However, note that the "from" address must be a registered email with * your Google App Engine account. */ function send($to, $from, $subject, $plain, $html) { $api_key = $this->api_key; $status = $this->AppMailRest->post('send', compact('api_key','to','from','subject','plain','html')); return $status; } }
的appmail.config.php loooks這樣
$app1DB = new mysqli("localhost", "root", "", "ast"); $app1RSP = $app1DB->query("SELECT app_id FROM Application WHERE emails_sent fetch_assoc(); $app_id = $app1Object['app_id']; define('APPMAIL_API_KEY', 'JLQ7P5SnTPq7AJvLnUysJmXSeXTrhgaJ'); define('APPMAIL_URL', "http://$app_id.appspot.com/"); $app1RSP->free(); $app1DB->close();
基本上我需要得到變量APPMAIL_URL/$ APP_ID在每個循環運行的類。
@Frosty Z如果我在循環之前加入了appmail.core.php,我想我在每個循環中都會得到相同的APPMAIL_URL(它在appmail.config.php中),因爲它只會從D b 。我需要在每個循環中獲得不同的APPMAIL_URL。 – Michael 2011-03-29 13:53:34
@邁克爾:那麼你的對象被定義爲錯誤的。定義/初始化對象一次,然後在每次迭代中重置APPMAIL_URL。 – 2011-03-29 14:13:52
編輯答案... – 2011-03-29 14:40:53