duanlie3187 2014-09-08 14:14
浏览 26

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

I am currently dealing with a third-party library that defines a global username/password constants in a global namespace. I do not want to modify the library source code at the same time I need to connect with different credentials (i.e. more than one set). Therefore, editing the library source code is not the solution. To be honest even without this requirement this is not a good practice to modify the 3rd-party libraries source code as it may lead to unexpected results when updating.

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');

This, however, still outputs the warning in CLI

Is there any way to suppress those warnings?

  • 写回答

1条回答 默认 最新

  • 我在西湖1 2014-09-08 14:26
    关注

    This is their config file:
    https://github.com/OpenSRS/osrs-toolkit-php/blob/master/opensrs/openSRS_config.php.template

    From their documentation you are meant to define these constant in a renamed copy of that.

    Check your dist for an existing file called: openSRS_config.php

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测