I have seen some code from Stack Overflow. It confused me a lot. I just don't know whether some part is missing or not.
The code is as follows:
$ch = curl_init($captcha_url);
curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
curl_setopt($ch, CURLOPT_FILE, $fp);
$out2['result'] = curl_exec($ch);
$out2['error'] = curl_error($ch);
$out2['info'] = curl_getinfo($ch);
curl_close($ch);
I know $Out2['result']
is assigned here and result is the key and curl_exec($ch)
is value here. But i haven't seen $out2
declared as an array ?
Is this missing from this code or can we apply like this ?
In short, yes.
PHP isn't (at the moment) that explicit about declaring data types when creating variables - unlike other languages, although I'm sure PHP are changing their ways.
Although you can do this, it's advised (good practice) to declare the data type of the variable before assigning value(s) to it.
When a value is first assigned to $out2
, it is initialized as whatever datatype in needs to be. In this case, an array.