我目前正在处理一个第三方库,该库在全局 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/