从withing名称空间调用函数时出现500内部错误

时间:2017-12-09 20:57:30

标签: php namespaces

我有一个包含多个函数的文件,这些函数位于命名空间LOM中。一个叫get_cart_total()。当我在该文件之外调用该函数时,一切都很好......

$total_value = LOM\get_cart_total()[0];效果很好。

但当我在该文件中时,调用它我会得到500内部错误...

$total_value = get_cart_total()[0];失败(我在文件命名空间LOM中)。

即使在var_dump()上执行get_cart_total(),也会导致 在命名空间文件中出现500错误,但var将其转储到命名空间文件中细

注意:PHP版本是7.0.25。

有什么想法吗?

根据评论请求,get_cart_total()的代码是......

    //For updating the subtotal and/or total in the shopping cart
function get_cart_total($additional_parameters_array = array()){
    $db = \DB::getInstance(); //For including the database object/class.
    global $user; //Get the $user object 

    //Get list of product ids for this order
    $products_array = get_product_id_array_for_order_in_process();

    //Calculate the $sub_total.
    $sub_total = 0;
    foreach($products_array as $product_id){
        if($product_id == 0){ //It's tutoring, so do this differently than other things.
            //Get the number of hours of tutoring that are currently in the cart.
            $hrs = tutoring_hrs_in_cart();

            $sub_total = $sub_total + tutoring_total_price($hrs);
        } else { //It's not tutoring, so just get the price and add it in.
            $sub_total = $sub_total + get_product_price($product_id);   
        }           
    }

    //Apply payment method fee_discount if applicable
        //Get the fee_discount for an order that's in process based on the products and subtotal.
        $fee_discount = get_payment_method_fee_discount_for_order_in_process();

        $total = $fee_discount + $sub_total;


    //Apply store credit
        //See if we're applying store credit.
        $apply_store_credit = applying_store_credit_for_order_in_process();

        //We are applying store credit, so reduce $total by that amount.
        if($apply_store_credit == 1){
            $store_credit_amount = get_store_credit($user->data()->id);
            $total = $total - $store_credit_amount;
        }

        //We can't have a negative order total, so if it's negative, just make the $total = 0.
        if($total < 0){
            $total = 0;
        }           

    $total_array[] = $total;
    $total_array[] = $sub_total;

    return $total_array;
}

2 个答案:

答案 0 :(得分:0)

我假设您正在使用课程

您可以使用&#34; self&#34;

在同一个类中的另一个方法中调用方法
$total_value = self::get_cart_total()[0];

希望这有帮助。

答案 1 :(得分:0)

我最终陷入了一个循环,我从另一个get_payment_method_fee_discount_for_order_in_process()中调用了一个函数get_cart_total(),然后调用了该函数中的原始函数等等。

请继续开车...这里没什么可看的。