是什么导致PHP中的变量未设置?

时间:2019-07-18 20:05:46

标签: php

我有以下代码:

$ProductMatched= false;
foreach($this->ActiveSubscription->ratePlans as $ratePlan) {

    if(property_exists($ratePlan, 'lastChangeType') && $ratePlan->lastChangeType=='Remove') continue;

    $productRatePlanId = $ratePlan->productRatePlanId;

    // handle setup fee and sign-up discounts differently from other subscription rate plan items
    if(stripos($ratePlan->ratePlanName, 'Setup Fee') !== false || stripos($ratePlan->ratePlanName, 'Sign-up Discount') !== false) {
        if(!$IsComp) {

            if(stripos($ratePlan->ratePlanName, 'Setup Fee') !== false || stripos($ratePlan->ratePlanName, 'Sign-up Discount') !== false) {
                $HasProducts = true;
                $simpleProduct = [
                    'productName' => $ratePlan->ratePlanName,
                    'billingRateGUID' => $ratePlan->productRatePlanId,
                    'productCost' => 0.00,
                    'productProratedCost' => 0.00,
                    'addon_id' => null,
                    'isPurchased' => true
                ];
                $simpleProduct['productCost'] = (sizeof($ratePlan->ratePlanCharges) > 0 ? money_format('%i', (stripos($ratePlan->ratePlanName, 'Setup Fee') !== false ? $ratePlan->ratePlanCharges[0]->price : $ratePlan->ratePlanCharges[0]->discountAmount)) : 0.00);
                $simpleProduct['productProratedCost'] = $simpleProduct['productCost'];
                if(stripos($ratePlan->ratePlanName, 'Sign-up Discount') !== false || stripos($ratePlan->ratePlanName, 'Individual') !== false) {
                    $pdfData->primaryMember['products'][] = $simpleProduct;
                    $simpleProduct['productName'] = (stripos($ratePlan->ratePlanName, 'Sign-up Discount') !== false ? 'Sign-up Discount' : 'Couple\'s Plan Setup Fees');
                    $simpleProduct['isPurchased'] = false;
                    $pdfData->secondaryMember['products'][] = $simpleProduct;
                } else {
                    $pdfData->secondaryMember['products'][] = $simpleProduct;
                    $simpleProduct['productName'] = (stripos($ratePlan->ratePlanName, 'Sign-up Discount') !== false ? 'Sign-up Discount' : 'Individual Plan Setup Fees');
                    $simpleProduct['isPurchased'] = false;
                    $pdfData->primaryMember['products'][] = $simpleProduct;
                }
                $ProductMatched = true;
                continue; // move on to next rate plan item in subscription
            }
        } else {
            $compBasePlanName = $ratePlan->ratePlanName;
            if(stripos($compBasePlanName, 'Setup Fee') !== false || stripos($compBasePlanName, 'Sign-up Discount') !== false) {
                $HasProducts = true;
                $SetupAndDiscountAmount = ($this->PolicyMemberCount == 2 ? 39.90 : 19.95);
                $simpleProduct = [
                    'productName' => (stripos($compBasePlanName, 'Sign-up Discount') !== false ? 'Sign-up Discount' : ($this->PolicyMemberCount == 2 ? 'Couple\'s' : 'Individual').' Plan Setup Fees'),
                    'comp_billing_rate_guid' => $ratePlan->productRatePlanId,
                    'productCost' => money_format('%i', $SetupAndDiscountAmount),
                    'productProratedCost' => money_format('%i', $SetupAndDiscountAmount),
                    'addon_id' => null,
                    'isPurchased' => true
                ];
                if($this->PolicyMemberCount == 2) {
                    $pdfData->secondaryMember['products'][] = $simpleProduct;
                    $simpleProduct['productName'] = (stripos($compBasePlanName, 'Sign-up Discount') !== false ? 'Sign-up Discount' : 'Individual Plan Setup Fees');
                    $simpleProduct['isPurchased'] = false;
                    $pdfData->primaryMember['products'][] = $simpleProduct;
                } else {
                    $pdfData->primaryMember['products'][] = $simpleProduct;
                    $simpleProduct['productName'] = (stripos($compBasePlanName, 'Sign-up Discount') !== false ? 'Sign-up Discount' : 'Couple\'s Plan Setup Fees');
                    $simpleProduct['isPurchased'] = false;
                    $pdfData->secondaryMember['products'][] = $simpleProduct;
                }
                $ProductMatched = true;
                continue; // move on to next rate plan item in subscription
            }
        }
    } else {
        if( !$IsComp )
        {
            foreach($pdfData->primaryMember['products'] as &$product) {
                if($product['billingRateGUID'] == $productRatePlanId) {
                    $HasProducts = true;
                    if($this->AccountType != 'Comp') {
                        $product['productProratedCost'] = money_format('%i', (property_exists($ratePlan, 'ratePlanCharges') && is_array($ratePlan->ratePlanCharges) && sizeof($ratePlan->ratePlanCharges) > 0 ? $ratePlan->ratePlanCharges[0]->price : $product['productCost']));
                    }
                    $product['isPurchased'] = true;
                    $ProductMatched = true;
                    continue 2; // move on to next rate plan item in subscription
                }
            }
            foreach($pdfData->secondaryMember['products'] as &$product) {
                if($product['billingRateGUID'] == $productRatePlanId) {
                    $HasProducts = true;
                    if($this->AccountType != 'Comp') {
                        $product['productProratedCost'] = money_format('%i', (property_exists($ratePlan, 'ratePlanCharges') && is_array($ratePlan->ratePlanCharges) && sizeof($ratePlan->ratePlanCharges) > 0 ? $ratePlan->ratePlanCharges[0]->price : $product['productCost']));
                    }
                    $product['isPurchased'] = true;
                    $ProductMatched = true;
                    continue 2; // move on to next rate plan item in subscription
                }
            }
        }
        else
        {
            $productId = $this->lookupProductIdFromRatePlanId($productRatePlanId);
            foreach($pdfData->primaryMember['products'] as &$product) {
                // aside from product_id, we also need to verify it's the right cycle (yr/mo)
                if($product['product_id'] == $productId && $product['cycle_id'] == $this->Account->cycle_id) {
                    $HasProducts = true;
                    if($this->AccountType != 'Comp') {
                        $product['productProratedCost'] = money_format('%i', (property_exists($ratePlan, 'ratePlanCharges') && is_array($ratePlan->ratePlanCharges) && sizeof($ratePlan->ratePlanCharges) > 0 ? $ratePlan->ratePlanCharges[0]->price : $product['productCost']));
                    }
                    $product['isPurchased'] = true;
                    $ProductMatched = true;
                    continue 2; // move on to next rate plan item in subscription
                }
            }
            foreach($pdfData->secondaryMember['products'] as &$product) {
                // aside from product_id, we also need to verify it's the right cycle (yr/mo)
                if($product['product_id'] == $productId && $product['cycle_id'] == $this->Account->cycle_id) {
var_dump('1.) RatePlanName: ' . $ratePlan->ratePlanName);
                    $HasProducts = true;
                    if($this->AccountType != 'Comp') {
                        $product['productProratedCost'] = money_format('%i', (property_exists($ratePlan, 'ratePlanCharges') && is_array($ratePlan->ratePlanCharges) && sizeof($ratePlan->ratePlanCharges) > 0 ? $ratePlan->ratePlanCharges[0]->price : $product['productCost']));
                    }
                    $product['isPurchased'] = true;
                    $ProductMatched = true;
var_dump('2.) ProductMatched: ' . $ProductMatched);
                    continue 2; // move on to next rate plan item in subscription
                }
            }
        }

    }
var_dump('3.) ProductMatched: ' . $ProductMatched);
exit;

    if(!$ProductMatched) {
        // our most valiant efforts have failed. Log the error and throw an exception
        $this->logPolicyError('Subscription rate plan \''.$ratePlan->ratePlanName.'\' ("'.$ratePlan->productRatePlanId.'") does not match any valid products for region ('.$this->Region['region_id'].'). Exiting.');
        throw new Exception('Subscription rate plan \''.$ratePlan->ratePlanName.'\' ("'.$ratePlan->productRatePlanId.'") does not match any valid products for region ('.$this->Region['region_id'].'). Exiting.');
    }
}

我在这里得到的var_dumps的输出如下:

string(43) "1.) RatePlanName: Annual Couple's Plan Comp"
string(21) "2.) ProductMatched: 1"
string(20) "3.) ProductMatched: "

我正在尝试确定第三个var_dump尚未设置。我尝试将$ProductMatched实例化到函数顶部,但是对此没有任何帮助。是什么会导致像这样取消设置变量?

0 个答案:

没有答案