2017-12-09 6 views
-1

Ich habe eine Datei mit mehreren Funktionen, die im Namespace LOM sind. Einer heißt get_cart_total(). Wenn ich außerhalb dieser Datei bin, die die Funktion aufruft, ist alles gut ...500 Interner Fehler beim Aufrufen der Funktion aus dem Namespace

$total_value = LOM\get_cart_total()[0]; funktioniert gut.

Aber wenn ich in dieser Datei bin, nenne es mir einen 500 Interner Fehler bekommen ...

$total_value = get_cart_total()[0]; nicht (ich bin in der Datei LOM Namespace).

Auch eine var_dump() auf get_cart_total() bewirkt, dass die 500-Fehler von innerhalb die Datei Namespace zu tun, aber var es außerhalb die Datei Namensraum ist in Ordnung Dumping.

Hinweis: PHP-Version ist 7.0.25.

Irgendwelche Ideen?

pro Kommentar Anfrage, der Code für get_cart_total() ist ...

//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; 
} 

Antwort

0

Ich nehme an, Sie verwenden eine Klasse

Sie können eine Methode in einem anderen Verfahren innerhalb derselben Klasse aufrufen mit „Selbst“

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

Hoffe, das hilft.

+0

Ich bin eigentlich nicht in einer Klasse. Der Versuch, Ihre Lösung zu testen, ergab 'Fataler Fehler: Kann" self "nicht verwenden, wenn kein Klassenbereich aktiv ist. – gtilflm

+0

Überprüfen Sie Ihre PHP-Fehlerprotokolldatei auf die genaue Fehlerzeile. –

0

landete ich mich in eine Schleife bekommen, wo ich eine Funktion get_payment_method_fee_discount_for_order_in_process() aus einem anderen get_cart_total() genannt, dann die ursprüngliche Funktion in diesem einen usw.

Bitte halten Sie fahren ... wir haben hier nichts zu sehen.

Verwandte Themen