2017-12-09 8 views
-1

私は名前空間LOMの中にいくつかの関数を持つファイルを持っています。 1つはget_cart_total()と呼ばれています。私がそのファイルの外にいるときに関数を呼び出すと、すべてがうまくいきます...500名前空間withingから関数を呼び出すときの内部エラー

$total_value = LOM\get_cart_total()[0];は問題ありません。

しかし、私はそのファイルによ、私は500内部エラーを取得し、それを呼び出す...

$total_value = get_cart_total()[0];は(私はLOMの名前空間ファイルにいます)が失敗しました。でもget_cart_total()var_dump()をやっ

内の名前空間ファイルから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; 
} 

答えて

0

...です

$total_value = self::get_cart_total()[0]; 

希望します。

+0

私はクラスには実際にはいません。あなたの解決策を試してみると '致命的なエラー:クラススコープがアクティブでないときに" self "を使うことはできません。 – gtilflm

+0

エラーの正確な行については、PHPエラーログファイルを確認してください。 –

0

は私が

こちらを参照するには...何を駆動していない所に保管してください、私は別のget_cart_total()の中から一つの機能get_payment_method_fee_discount_for_order_in_process()と呼ばれるループ、その1つの中に、元の機能などに自分自身を取得することになりました。

関連する問題