2010-12-08 11 views
0

私は以下のような形式で情報を返すオブジェクトを扱っています...いくつかの領域を節約するために情報が少し繰り返されるような細部を削除しました。PHPオブジェクトから詳細を抽出するにはどうすればよいですか?

ISC_QUOTE_ITEM Object (
    [type:protected] => 1 
    [id:protected] => 4cff5974138c9 
    [hash:protected] => cd2a8393493a286cf1fe97d92a947719 
    [productData:protected] => 
    [productId:protected] => 28 
    [variationId:protected] => 0 
    [variationOptions:protected] => Array () 
    [quantity:protected] => 1 
    [originalOrderQuantity:protected] => 0 
    [name:protected] => Mac Pro 
    [basePrice:protected] => 2799.0000 
    [sku:protected] => 
    [wrapping:protected] => Array () 
    [configuration:protected] => Array () 
    [eventDate:protected] => Array () 
    [eventName:protected] => 
    [parentId:protected] => 
    [quote:protected] => ISC_QUOTE Object (
     [customerId:protected] => 
     [customerGroupId:protected] => 
     [discounts:protected] => Array () 
     [addresses:protected] => Array ( 
      [4cff2f55b0fcd] => ISC_QUOTE_ADDRESS_SHIPPING Object (
       [shippingMethod:protected] => 
       [shippingCache:protected] => 
       [handlingCost:protected] => 0 
       [quote:protected] => ISC_QUOTE Object *RECURSION* 
       [type:protected] => shipping 
       [id:protected] => 4cff2f55b0fcd 
       [firstName:protected] => asd 
       [lastName:protected] => asd 
       [company:protected] => asd 
       [phone:protected] => asd 
       [email:protected] => [email protected] 
       [address1:protected] => asd 
       [address2:protected] => 
       [zip:protected] => 62990 
       [city:protected] => asd 
       [state:protected] => Array (
        [id] => 0 
        [iso2] => 
        [name] => asd 
       ) 
       [country:protected] => Array (
        [id] => 99 
        [name] => India 
        [iso2] => IN 
       ) 
       [cachedTotals:protected] => Array () 
       [customFields:protected] => Array () 
       [saveAddress:protected] => 
       [customerAddressId:protected] => 0 
      ) 
      [4cff2f55cc2b6] => ISC_QUOTE_ADDRESS Object (
       [handlingCost:protected] => 
       [quote:protected] => ISC_QUOTE Object *RECURSION* 
       [type:protected] => billing 
       [id:protected] => 4cff2f55cc2b6 
       [firstName:protected] => asd 
       [lastName:protected] => asd 
       [company:protected] => asd 
       [phone:protected] => asd 
       [email:protected] => [email protected] 
       [address1:protected] => asd 
       [address2:protected] => 
       [zip:protected] => 62990 
       [city:protected] => asd 
       [state:protected] => Array (
        [id] => 0 
        [iso2] => 
        [name] => asd 
       ) 
       [country:protected] => Array (
        [id] => 99 
        [name] => India 
        [iso2] => IN 
       ) 
       [cachedTotals:protected] => Array () 
       [customFields:protected] => Array () 
       [saveAddress:protected] => 
       [customerAddressId:protected] => 0 
      ) 
     ) 
     [coupons:protected] => Array () 
     [giftCertificates:protected] => Array () 
     [items:protected] => Array (
      [0] => ISC_QUOTE_ITEM Object (
       [type:protected] => 1 
       [id:protected] => 4cff2f55b11d2 
       [hash:protected] => 587e0ee453488554f782b20f3c928916 
       [productData:protected] => 
       [productId:protected] => 24 
       [variationId:protected] => 0 
       [variationOptions:protected] => Array () 
       [quantity:protected] => 3 
       [originalOrderQuantity:protected] => 0 
       [name:protected] => Apple iPod Socks 
       [basePrice:protected] => 29.0000 
       [sku:protected] => 
       [wrapping:protected] => Array () 
       [configuration:protected] => Array () 
       [eventDate:protected] => Array () 
       [eventName:protected] => 
       [parentId:protected] => 
       [quote:protected] => ISC_QUOTE Object *RECURSION* 
       [discounts:protected] => Array () 
       [isCustomPrice:protected] => 
       [addressId:protected] => 4cff2f55b0fcd 
       [cachedTotals:protected] => Array () 
       [inQuote:protected] => 1 
       [inventoryChecking:protected] => 1 
       [weight:protected] => 1.0000 
       [fixedShippingCost:protected] => 0.0000 
      ) 
      [1] => ISC_QUOTE_ITEM Object (
       [type:protected] => 1 
       [id:protected] => 4cff58167d29f 
       [hash:protected] => 1da6aa898763172b8f7b9d8097d37f42 
       [productData:protected] => 
       [productId:protected] => 23 
       [variationId:protected] => 0 
       [variationOptions:protected] => Array () 
       [quantity:protected] => 1 
       [originalOrderQuantity:protected] => 0 
       [name:protected] => Apple In-Ear Headphones with Remote and Mic 
       [basePrice:protected] => 79.0000 
       [sku:protected] => 
       [wrapping:protected] => Array () 
       [configuration:protected] => Array () 
       [eventDate:protected] => Array () 
       [eventName:protected] => 
       [parentId:protected] => 
       [quote:protected] => ISC_QUOTE Object *RECURSION* 
       [discounts:protected] => Array () 
       [isCustomPrice:protected] => 
       [addressId:protected] => 4cff2f55b0fcd 
       [cachedTotals:protected] => Array () 
       [inQuote:protected] => 1 
       [inventoryChecking:protected] => 1 
       [weight:protected] => 2.0000 
       [fixedShippingCost:protected] => 0.0000 
      ) 
      [2] => ISC_QUOTE_ITEM Object *RECURSION* 
     ) 
     [isSplitShipping:protected] => 
     [cachedTotals:protected] => Array () 
     [hasFreeShipping:protected] => 
     [appliedStoreCredit:protected] => 0 
     [appliedDiscountRules:protected] => Array () 
     [customerMessage:protected] => 
     [staffNotes:protected] => 
     [orderStatus:protected] => 0 
     [orderId:protected] => 
     [discountsEnabled:protected] => 1 
    ) 
    [discounts:protected] => Array () 
    [isCustomPrice:protected] => 
    [addressId:protected] => 4cff2f55b0fcd 
    [cachedTotals:protected] => Array () 
    [inQuote:protected] => 1 
    [inventoryChecking:protected] => 1 
    [weight:protected] => 3.0000 
    [fixedShippingCost:protected] => 0.0000 
) 

私はそれは、それぞれ4cff5974138c9Mac Proなどを読み取るようになどのID、名前、などの詳細を抽出する必要があります。どうやってやるの?

+0

読み込み不可能な配列... – pltvs

答えて

0

あなたは(ISC_QUOTE_ITEMが対象となっている - MyClassを言う)、そのクラスの関数を呼び出す必要がありそれはアクセスすることができ、保護変数

編集
を返します。私は正しかった。このよう

-

お持ちでない場合は、あなたのクラスMyClass内部の機能を追加します。

public function getName() 
{ 
    return $this->name; 
} 

そして、あなたのコードでは、あなたがこれを行うことができます: -

echo $obj->getName(); 

読むhttp://php.net/manual/en/language.oop5.visibility.phpあなたは反射構造物を使用することにより、これを行うことができ、変数

+0

あなたは正解です.. – sangeetha

+0

あなたは歓迎です –

0

の種類の可視性の詳細については:

例は、http://www.php.net/manual/en/reflectionclass.getproperties.phpから取った:

<?php 
class Foo { 
    public $foo = 1; 
    protected $bar = 2; 
    private $baz = 3; 
} 

$foo = new Foo(); 

$reflect = new ReflectionClass($foo); 
$props = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); 

foreach ($props as $prop) { 
    print $prop->getName() . "\n"; 
} 

var_dump($props); 

?> 

また、$barが返されます。http://www.php.net/manual/en/reflectionproperty.getvalue.php#98643をご覧ください。保護された属性の値を返す方法が示されています。

関連する問題