0

I'm getting this error when I run the script

php Fatal error:  Cannot redeclare class AppMailCore in /appmail.core.php on line 10

I need to make loop that will also use some variables from a class file . The code from main.php looks like this :

   $iesc = 1;
 while($iesc less than 5)
{
include('includes/appmail.core.php');
---

I used "less than " in the code above 'cause I don't know to unescape "<" symbold within the pre markup .

I understand that I'm not allowed to re-delcare the class but I don't know how to make the class variables run through the loop . appmail.core.php looks like this

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;
  }
}

the appmail.config.php loooks like this

  $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();

Basically I need to get variable APPMAIL_URL/$app_id in the class on each loop run.

1 Answer 1

0

Why aren't you doing the include before the loop ?

Another tip: use include_once ?

Third tip: include directly appmail.config.php if you need a constant from it, not appmail.core.php ?

EDIT

Basically I need to get variable APPMAIL_URL/$app_id in the class on each loop run.

If its value is supposed to change through the script execution (as I just saw), then you shouldn't define it as a constant.

Sign up to request clarification or add additional context in comments.

5 Comments

@Frosty Z If I include the appmail.core.php before the loop I think I'm getting the same APPMAIL_URL(which is in the appmail.config.php ) on each loop as it will be retrieved only once from the db . I need to get different APPMAIL_URL on each loop .
@Michael: then your object is defined wrong. Define/initiate the object once, then reset the APPMAIL_URL on each iteration.
@Frosty Z can you please elaborate your answer or provide some code? . I've tried 100 methods today and couldn't make it work .. mostly 'cause I don't have a very good OOP understanding I think :(
@Marc B how can I reset the APPMAIL_URL ? that's all I need.. to reset the APPMAIL_URL based on the $app_id retrieved from database. I don't have a very good OOP understanding .
I finally figured out how to fix it .. thanks a lot for your help !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.