为什么我的Twitter应用程序返回端口错误?

Que*_*ner 8 php twitter oauth

我已经做了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";
}
Run Code Online (Sandbox Code Playgroud)

hak*_*kre 7

这是OAuth.php文件中的错误,它访问数组的索引,而不执行索引检查.

显然,编码器/ ETTE是谁写的,这是很聪明,聪明的使用错误抑制操作@,而不是做一个适当的索引检查-懒惰(假定最好的).

将此报告为上游错误,修复很简单:

$parts = parse_url($this->http_url) + array('port'=>NULL, 'path'=>NULL);
Run Code Online (Sandbox Code Playgroud)

并删除两个@运算符.


Sha*_*kka 5

发生这种情况是因为parse_url()无法保证返回端口号(强调我的):

如果省略component参数,则返回关联数组. 阵列中至少存在一个元素.

$port = (array_key_exists('port', $parts) ? $parts['port'] : 80);如果您不想触摸,请尝试使用类似隐藏通知的内容error_reporting.