php sınıfı kapsamı tüm sınıf üyeleri erişmiyorsunuz olmayan bir yöntemi işlevi çağırırken

1 Cevap

Yani ben ondan denilen varlık sınıfını kullanan bir sınıf içinde tek başına bir işlevi kullanıyorum. İşte fonksiyonu bulunuyor

function catalogProductLink($product_id,$product_name,$categories=true) {
    //This is the class that the function is called from
    global $STATE;
if ($categories) {
    //The $STATE->category_id is the property I want to access, which I can't
    if (is_array($STATE->category_id)) {
        foreach($STATE->category_id as $cat_id) {
            if ($cat_id == 0) continue;
            $str .= "c$cat_id/";
        }
    }
}
$str .= catalogUrlKeywords($product_name).'-p'.$product_id.'.html';
return $str;
}

Ve burada $ DEVLET sınıf içinde yapılıyor işlev çağrısı, bulunuyor.

$redirect = catalogProductLink($this->product_id, $tempProd->product_name, true, false);

The object that I need access to is the $STATE object that has been declared global. Prior to this function call there are lots of public properties populated, but when I look at the $STATE object within the function scope it loses all the properties but one, product_id. The property that matters for this function is the category_id property, which is an array of category id's.

Ben $ DEVLET nesne ve nasıl ben onlara ulaşabiliyorsunuz tüm kamu özelliklerine erişimi yok neden merak ediyorum.

1 Cevap

catalogUrlKeywords() Ne yapıyor? Ben $STATE Bu MEZUNLARI korkunç bir tasarım gibi geliyor modifiying bahse. global bir çerçeve ayrılmaz bir parçası ise, KOŞ!

Edit

Yoksa sadece category_id almak ve onunla yapılabilir isteğe bağlı bir parametre ekleyebilirsiniz. Belki yerine $categories=true, yapmak zorunda $categories category_id Sitesinden veya sıfır bir dizi çekmek.

function catalogProductLink($product_id,$product_name,$category_ids=0) {