开发者

PHP object, how to reference?

How do you point to the cid and get the value?

$item->?

array(1) {
  [0]=>
  object(__PHP_Incomplete_Class)#4 (4) {
    ["__PHP_Incomplete_Class_Name"]=>
    string(7) "Product"
    ["_param:protected"]=>
    array(40) {
      ["pid"]=>
      string(3) "540"
      ["cid"]=>
      string(2) "22"
      ["sid"]=>
      string(1) "1"
      ["tid"]=>
      string(1) "9"
      ["sales_volume"]=>
      string(1) "0"
      ["preorder_volume"]=>
      string(1) "0"
      ["viewed"]=>
      string(1) "0"
      ["weight"]=>
      string(4) "0.00"
      ["delivery_type"]=>
      string(6) "postal"
      ["cash_price"]=>
      string(4) "0.00"
      ["coupon_price"]=>
      string(4) "0.00"
      ["coupon_require"]=>
      NULL
      ["member_price"]=>
      NULL
      ["discount_code"]=>
      NULL
      ["special_offer"]=>
      string(1) "0"
      ["lan"]=>
      string(13) "eng,tchi,schi"
      ["special_offer_price"]=>
      string(4) "0.00"
      ["special_offer_begin"]=>
      string(19) "2010-09-06 11:25:05"
      ["special_offer_end"]=>
      string(19) "2010-09-06 11:25开发者_运维技巧:05"
      ["bonus_point"]=>
      string(1) "0"
      ["tax"]=>
      string(4) "0.00"
      ["release_date"]=>
      string(19) "2010-09-06 11:25:05"
      ["begin_datetime"]=>
      string(19) "2010-07-13 14:41:26"
      ["end_datetime"]=>
      NULL
      ["delivery_status"]=>
      string(4) "24hr"
      ["stock"]=>
      string(1) "0"
      ["status"]=>
      NULL
      ["discon"]=>
      string(1) "0"
      ["product_desc"]=>
      string(0) ""
      ["model_num"]=>
      string(8) "ATH-BT03"
      ["rating"]=>
      string(0) ""
      ["recycle_id"]=>
      array(2) {
        [0]=>
        string(1) "5"
        [1]=>
        string(2) "20"
      }
    }
    }
    ["doc:private"]=>
    object(DOMDocument)#5 (0) {
    }
  }
}


Class property _param is protected and you can't get access to this one from outside. Try to use reflection. You can find how to make private/protected property is public here http://mark-story.com/posts/view/using-the-php-reflection-api-for-fun-and-profit. May be it helps.


Looks like a pretty weirdly mixed object.

If I'm following correctly, it's an array that contains an object that has a property named _param that is an array with the key cid.

$item[0]->_param['cid']


The _param member is declared as protected, and can only be accessed from within the class itself, or from parent or inherited classes. The way to access this variable from outside of the class is to create and call a "getter" method, which would look like:

function getCid() {
    return $this->_param['cid'];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜