Reputation: 75
I would like to ask how we can put into an array a variable reference from the current object.
In my case i have an array used for curl post and some fields are static (grant type & scope) while others (id & secret) are dynamic.
More specifivally i want to put the id & the secret as shown below:
$headers = [
'client_id='=> $this->id,
'client_secret='=>$this->secret,
'grant_type='=>'client_credentials',
'scope='=>'public'
];
....
....
curl_setopt($s, CURLOPT_HTTPHEADER, $headers);
I am getting a "PHP Fatal error: Constant expression contains invalid operations in ..." for the second & third row.
Upvotes: 1
Views: 48
Reputation: 1039
This should be
$headers = [
"client_id: {$this->id}",
"client_secret: {$this->secret}",
"grant_type: client_credentials",
"scope: public"
];
....
....
curl_setopt($s, CURLOPT_HTTPHEADER, $headers);
Upvotes: 0
Reputation: 752
For headers you should use something like
array('Content-type: text/plain', 'Content-length: 100')
not associative array. See http://php.net/manual/en/function.curl-setopt.php
Upvotes: 1