Problem using require in a class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kong Chun Ho
    New Member
    • Jul 2010
    • 34

    #1

    Problem using require in a class

    Code:
    <?
    class LibertyReserve {
    require ('config.php');
    public function sendMoney($amount, $currency=$DEFCurrency, $target, $memo) {
    require('config.php');
    $content = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9');
    for ($i=0; $i!=$length;$i++){
    $RandomString_Each = rand (0,61);
    $RandomString .= $content[$RandomString_Each];
    }
    $rid = $RandomString;
    $request = '
    <TransferRequest id="' . $rid . '">
    <Auth>     
    <ApiName>' . $APINAME . '</ApiName>
    <Token>' . $auth . '</Token>
    </Auth>
    <Transfer>
    <TransferType>transfer</TransferType>
    <Payer>' . $LRAC . '</Payer>
    <Payee>' . $target . '</Payee>
    <CurrencyId>' . $currency . '</CurrencyId>
    <Amount>' . $amount . '</Amount>
    <Memo>' . $memo . '</Memo>
    <Anonymous>false</Anonymous>
    </Transfer>
    </TransferRequest>
    ';
    $url = 'https://api.libertyreserve.com/xml/transfer.aspx?req=' . $request;
    $response = file_get_contents($url);
    echo $response;
    }
    }
    ?>
    I got:
    Parse error: syntax error, unexpected T_REQUIRE_ONCE, expecting T_FUNCTION in C:\inetpub\wwwr oot\LRapi\class \LibertyReserve .class.php on line 3

    Note: I am requiring 2 config.php, it is NOT a mistake, because i can't use var. in "sendMoney" if i require the file outside "sendMoney" function. And the another config.php have contain $DEFCurrency and $auth.
  • Kong Chun Ho
    New Member
    • Jul 2010
    • 34

    #2
    Anyone have solution?

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      It's a syntax error. It's also pretty obvious.

      You are attempting to require a file in a space that is reserved for the definition of member variables and methods. Move it to the outside of the class.

      Also, instead of requiring the file again, why don't you just try using the global keyword to define the variables you need in your method's scope?

      Comment

      Working...