为什么我的 Twitter 应用程序返回端口错误?
我制作了一个 Twitter 应用程序,用于简单地从我的网站发布推文,使用“twitteroauth”和“oauth”PHP 脚本此处。
一切正常,但我的错误日志给了我这个错误:
未定义索引:端口 OAuth.php 383
虽然这似乎并没有抑制我的脚本运行,但我想让我的错误日志免受干扰。并避免未来可能出现的问题。
知道为什么会发生这种情况吗?
作为参考,OAuth.php 中的代码错误日志指向的是这样的:
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";
}
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";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是 OAuth.php 文件中的一个错误,它访问数组的索引而不执行索引检查。
显然,编写此代码的编码器/ette 非常聪明地使用错误抑制运算符
@
而不是进行适当的索引检查 - 很懒(假设最好)。将其报告为上游错误,修复很简单:
并删除两个
@
运算符。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:
and removing the two
@
operators.发生这种情况是因为 parse_url() 不能保证返回端口号(强调我的):
如果您不想触摸您的
,请尝试使用类似
。$port = (array_key_exists('port', $parts) ? $parts['port'] : 80);
的内容来隐藏通知错误报告This happens because parse_url() is not guaranteed to return the port number (emphasis mine):
Try using something like
$port = (array_key_exists('port', $parts) ? $parts['port'] : 80);
to hide the notice if you wish to not touch yourerror_reporting
.此错误已得到修复。这是提交网址:
https://github.com/christiandavid/twitteroauth/commit/dd944c8de3123ae5e0f380b4a907c92903059fae
This bug has been fixed. Here is the commit url:
https://github.com/christiandavid/twitteroauth/commit/dd944c8de3123ae5e0f380b4a907c92903059fae