【问题标题】:Illegal string offset 'qty' Wordpress非法字符串偏移 'qty' Wordpress
【发布时间】:2017-08-14 21:31:13
【问题描述】:

我在使用 wordpress 时遇到了非法字符串偏移量 'qty' 的问题,我不知道如何解决。

非法的字符串偏移量'qty' public_html/wp-content/themes/freelancersvalley/includes/aecore/payments.php 在第 70 行

代码:

function ae_user_package_info($user_ID) {
    if (!$user_ID) return;
    global $ae_post_factory;
    $ae_pack = $ae_post_factory->get('pack');
    $packs = $ae_pack->fetch();
    $orders = AE_Payment::get_current_order($user_ID);
    $package_data = AE_Package::get_package_data($user_ID);
    foreach ($packs as $package) {
        $sku = $package->sku;
        if (isset($package_data[$sku]) && $package_data[$sku]['qty'] > 0) {
            if( $package->post_type == 'pack'){
                $order = get_post($orders[$sku]);
                if (!$order || is_wp_error($order) || !in_array($order->post_status, array('publish', 'pending'))) continue;
                    /**
                    * print text when company has job left in package
                    */
                    ?>
                    <p>

错在哪里?

【问题讨论】:

  • print_r($package_data); 里面有数量吗?

标签: php wordpress string offset


【解决方案1】:

您的错误意味着 $package_data[$sku] 是一个字符串而不是一个数组(正如您所期望的那样。

astackoverflow 中的偏移量是2(因为s 是0 而t1)。

要解决此问题,您需要确保 $package_data[$sku] 是一个数组,并且它包含一个名为 qty 的键。

我不确定它是否真的能“解决”你的问题,但如果你写:isset($package_data[$sku]['qty']) 而不是isset($package_data[$sku]),你可以避免错误

【讨论】:

  • 谢谢 mickmackusa,我写了你所说的,有新问题解析错误:语法错误,/home/frlley/domains/freelancersvalley.com/public_html/wp-content/themes 中的意外'{' /freelanceersvalley/includes/aecore/payments.php 第 72 行
  • 确保){ 之前的行中的每个开口( 都有一个结束)
  • 警告已解决!我写你的代码时出错了:)
  • 至于解决根本问题,您需要从一些放置良好的检查点开始调试,并将变量打印到屏幕上。我不是 Wordpress 人,所以祝你好运。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多