I'm trying to make a class for an api I'm using. I want to define the api token as a private variable, and concatenate it to different url strings (e.g. 'organizations', 'persons', 'contacts', etc.). The different urls will be different elements in an associative array.
Here's one way I'm doing it, and NetBeans says there's an error in the closing curly bracket of the __construct function: "Syntax error: unexpected }"
class MyCRM {
private $api_token;
public function __construct()
{
$this->api_token = "xxxxxxxxxxxxxx4ce124d75fb9zzzzzzzzzzz";
$url = array(
"organizations" => "https://api.service.com/v1/organizations?api_token=" . $this->api_token
)
} // <- Error is here
...the problem seems to stem fron concatenating the $this->api_token
to the url string.
The second way I've written the code was like this:
private $api_token = "zzzzzzzzzzzzzzzzzzce124d75fbxxxxxxxxx";
public $url = array(
"organizations" => "https://api.pipedrive.com/v1/organizations?api_token=" . $this->api_token // <- "Syntax error: unexpected variable '$this'
)
I'm looking at examples from php.net and other sources, not sure what I'm doing wrong. Please request more clarity if I'm not explaining well enough.