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

标签 php twitter oauth

我已经使用“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/

相关文章:

php - 更新需要查找 'newest' 行的查询

php - 在 php 中的 foreach 循环中增加数组元素?

javascript - 使用 Google Analytics 跟踪网站上的社交推文

OAuth 请求和访问 token

node.js - 创建 OAuth API 时的应用程序 token / secret

wcf - 使用 Azure ACS 和 OAuth 2.0 的 Facebook 式 API 访问场景 : how to implement app authorization?

php - 用于清理字符串的正则表达式

php - 在对象上使用 add() 后如何检索插入的 ID?

javascript - 使用ajax识别400请求

html - 社交媒体上的链接跟随按钮不起作用