php - 尝试声明已存在的全局常量时禁用警告

标签 php error-handling

我目前正在处理一个第三方库,该库在全局 namespace 中定义了全局用户名/密码常量。我不想在需要使用不同的凭据(即一组以上)连接的同时修改库源代码。因此,编辑库源代码不是解决方案。老实说,即使没有此要求,修改第三方库源代码也不是一个好习惯,因为在更新时可能会导致意外结果。

define('OSRS_USERNAME', $credentials[self::USERNAMETAG]);
define('OSRS_KEY', $credentials[self::PASSWORDTAG]);

$host = isset($credentials['testmode']) ? self::TESTHOST : self::LIVEHOST;
define('OSRS_HOST', $host);
define('OSRS_SSL_PORT', self::PORT);
//only now we can require the openSRS loader as it otherwise would define other values as contants for username & password
//@ is here to supress warnings about redefining the credentials constants in the 3rd party config file
//this is safe as just including the file shoould not throw if the script does not have any syntax errors
@require_once('OpenSRS/openSRS_loader.php');

但是,这仍然会在CLI中输出警告

有什么办法可以抑制那些警告?

最佳答案

这是他们的配置文件:
https://github.com/OpenSRS/osrs-toolkit-php/blob/master/opensrs/openSRS_config.php.template

从他们的文档中,您可以在重命名的副本中定义这些常量。

检查您的dist是否存在一个名为openSRS_config.php的现有文件

关于php - 尝试声明已存在的全局常量时禁用警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25726329/

相关文章:

php - 用颜色覆盖 png 图像 (php)

javascript - I.E(JavaScript、jQuery)中预期出现 ';' 异常

php - PHP页面在以下代码的第9行显示了解析错误,请帮助解决此问题

matlab - 不知道如何纠正: “In an assignment A(I) = B, the number of elements in B and I must be the same.”

Python:IndexError:列出超出范围的索引和类对象

c# - C# 中的 IErrorInfo

PHP Laravel 检查两个数组是否具有匹配的键值,如果是,则从数组 1 中取出一个元素并插入数组 2

php - Firestore REST API : Query parameters type of object

javascript - Laravel - 将 JSON 响应包装在文本区域中

PHP Session 过期事件