2016-04-06 36 views
2

我有一個PHP對象,看起來像這樣:如何訪問命名空間的php對象?

Array 
(
    [0] => Google\API\Response\Model\Goog Object 
     (
      [rp:Google\API\Response\Model\Goog:private] => 
      [sn:Google\API\Response\Model\Goog:private] => aaazzz999 
      [id:Google\API\Response\Model\Goog:private] => 105735459918379875 
      [c_id:Google\API\Response\Model\Goog:private] => 
      [st:Google\API\Response\Model\Goog:private] => 1 
      [m:Google\API\Response\Model\Goog:private] => 0 
      [sts:Google\API\Response\Model\Goog:private] => 1459918379875 
      [ts:Google\API\Response\Model\Goog:private] => 1459918379875 
      [t:Google\API\Response\Model\Goog:private] => 3 
      [replayed:Google\API\Response\Model\Goog:private] => 
      [zipped:Google\API\Response\Model\Goog:private] => 
      [broadcast:Google\API\Response\Model\Goog:private] => 
      [broadcast_media_url:Google\API\Response\Model\Goog:private] => 
     ) 

) 

如何訪問[SN:谷歌\ API \響應\型號\ goog:私人]數組值?

+0

'get_object_vars()' – aldrin27

+0

get_object_vars() – Jose

回答

1

問題不在於名稱空間,而是屬性具有私有可見性。這意味着只有內部方法才能訪問它們。爲了從外部訪問他們,他們需要公衆的知名度。

可能的解決方案是檢查Goog的類源,並查找可能返回屬性值的任何方法。私人屬性的類一般是通過公開方式揭露他們,比如像:

$value = $myArray[0]->getMediaUrl(); // example showing calling a public method