简体   繁体   English

php 在调用中使用变量

[英]php Using variable in an call

Fatal error: Access to undeclared static property: DTS\eBaySDK\Constants\GlobalIds::$stripped in /home/jimi13/public_html/dealpopup.com/ebayapi/finding/mine.php on line 334致命错误:访问未声明的 static 属性:DTS\eBaySDK\Constants\GlobalIds::$stripped in /home/jimi13/public_html/dealpopup.com/ebayapi/finding/mine.php 在线

$stripped = str_replace(' ', '', $country);
$stripped = preg_replace('/\s+/', '', $stripped);
echo $stripped;

need to take put stripped into this需要把它剥掉

$service = new Services\FindingService([
    'credentials' => $config['production']['credentials'],
    'globalId'    => Constants\GlobalIds::US
]);

need to put this in, but throws error需要把它放进去,但会抛出错误

$service = new Services\FindingService([
    'credentials' => $config['production']['credentials'],
    'globalId'    => Constants\GlobalIds::$stripped
]);

Here is a way you can access a constant variable in the class with namespace.这是一种可以使用命名空间访问 class 中的常量变量的方法。 If no namespace then you can remove the Constants namespace.如果没有命名空间,那么您可以删除常量命名空间。

namespace Constants;

class Hello {
  const WORLD = 'Hello World';
}

$world = 'WORLD';
echo constant('Constants\Hello::' . $world);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM