我已经使用“twitteroauth”和“oauth”PHP 脚本制作了一个 Twitter 应用程序来简单地从我的网站发布推文 here .
一切正常,但我的错误日志给我这个错误:
Undefined index: port 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";
}
最佳答案
这是 OAuth.php
文件中的一个错误,它访问数组的索引而没有执行索引检查。
显然,编写此代码的编码器/ette 非常聪明,使用错误抑制运算符 @
而不是进行适当的索引检查 - 懒惰(假设最好)。
将此报告为上游错误,修复很简单:
$parts = parse_url($this->http_url) + array('port'=>NULL, 'path'=>NULL);
并删除两个 @
运算符。
关于php - 为什么我的 Twitter 应用程序返回端口错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7469542/