php - php 在调用中使用变量
问题描述
致命错误:访问未声明的静态属性:DTS\eBaySDK\Constants\GlobalIds::$stripped in /home/jimi13/public_html/dealpopup.com/ebayapi/finding/mine.php 在第 334 行
$stripped = str_replace(' ', '', $country);
$stripped = preg_replace('/\s+/', '', $stripped);
echo $stripped;
需要把它剥掉
$service = new Services\FindingService([
'credentials' => $config['production']['credentials'],
'globalId' => Constants\GlobalIds::US
]);
需要把它放进去,但会抛出错误
$service = new Services\FindingService([
'credentials' => $config['production']['credentials'],
'globalId' => Constants\GlobalIds::$stripped
]);
解决方案
这是一种可以使用命名空间访问类中的常量变量的方法。如果没有命名空间,那么您可以删除常量命名空间。
namespace Constants;
class Hello {
const WORLD = 'Hello World';
}
$world = 'WORLD';
echo constant('Constants\Hello::' . $world);
推荐阅读
- spring-boot - Spring Boot Admin:没有刷新配置的选项
- c++ - C++ 语法头文件错误
- javascript - 如何将 PDFJS.getDocument 中从 canvas.toBlob() 创建的 url 保存到数组中?
- laravel - 如何使用 Yajra 数据表服务器端创建可点击的链接
- list - 如何将某些值映射到 Prolog 中的列表?
- keras - 如何在 LFW 数据集上训练 CNN?
- java - Selenium - 在 java 中编写错误检查的最佳方法?
- react-native - Expo相机中的强制编码方法
- python - 错误:TypeError:不能将序列乘以“列表”类型的非整数
- angular - Angular,检测当前屏幕在哪个元素上滑动