PHP "use" keyword error

Parse error: syntax error, unexpected ‘use’ (T_USE) in …/daily-email/daily-email.php on line 244

function get_constant_contact_list() {
    $cc_api_key = get_option('cc_api_key');
    $cc_secret_key = get_option('cc_secret_key');
    $cc_access_token = get_option('cc_access_token');

    use Ctct\ConstantContact;
    $cc = new ConstantContact($cc_api_key);
    
    $contacts = $cc->getContacts($cc_access_token);

    $results = $contacts->results;
    $email = $results[0]->email_addresses;
    echo $email[0]->email_address;
}

can anyone help me? why this error is occurring? and can I fix it?

Thanks in advance

EDIT
This post has been reformatted by enclosing the code block in 3 backticks
```
on their own lines.

Check out the PHP Manual:

http://php.net/manual/en/language.namespaces.importing.php

Are you using PHP >= 5.3

Are you missing an include/require file somewhere?

@John_Betong gave a link to documentation where you can read this:

The use keyword must be declared in the outermost scope of a file (the global scope)

You should move your use declaration outside the function

1 Like
    megazoid thank you very much

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.