I have made a Twitter app to simply post tweets from my web site, using the "twitteroauth" and "oauth" PHP scripts here.
Everything works, but my error logs are giving me this error:
Undefined index: port OAuth.php 383
Although this doesn't seem to be inhibiting my scripts from functioning, I'd like to keep my error logs free of noise. And avoid possible future issues.
Any idea why this is happening?
For reference the code in OAuth.php the error log is pointing to is this:
public function get_normalized_http_url() {
$parts = parse_url($this->http_url);
$port = @$parts['port']; <-- Line 383
$scheme = $parts['scheme'];
$host = $parts['host'];
$path = @$parts['path'];
$port or $port = ($scheme == 'https') ? '443' : '80';
if (($scheme == 'https' && $port != '443')
|| ($scheme == 'http' && $port != '80')) {
$host = "$host:$port";
}
return "$scheme://$host$path";
}
That is an error in the OAuth.php
file, it accesses an index of an array w/o performing an index check.
Obviously the coder/ette who wrote this was so clever-clever to use the error suppression operator @
instead of doing a proper index check - being lazy (to assume the best).
Report this as a bug upstream, a fix is trivial:
$parts = parse_url($this->http_url) + array('port'=>NULL, 'path'=>NULL);
and removing the two @
operators.
This happens because parse_url() is not guaranteed to return the port number (emphasis mine):
If the component parameter is omitted, an associative array is returned. At least one element will be present within the array.
Try using something like $port = (array_key_exists('port', $parts) ? $parts['port'] : 80);
to hide the notice if you wish to not touch your error_reporting
.
This bug has been fixed. Here is the commit url:
https://github.com/christiandavid/twitteroauth/commit/dd944c8de3123ae5e0f380b4a907c92903059fae
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With