Frage

Get object 's array value in php

 $obj = new Basecamp($bcUrl, $bcApikey, 'X', 'simplexml');

while print the object

    print_r($obj);

Get array as following:

Basecamp Object
(
    [request:protected] => 
    [baseurl:protected] => https://test.basecamphq.com/
    [format:protected] => simplexml
    [username:protected] => 5d4dsh8745hkf876kjdfhkfsd843ea46a
    [password:protected] => X
    [request_body:protected] => 
)

I want to take value of [baseurl:protected] i.e get 'https://test.basecamphq.com/' only from this object.

War es hilfreich?

Lösung

[baseurl:protected] means that the object has a property called baseurl which has a visibility of protected. That means you can specifically not access it directly from outside the class. Look in the documentation of the class how you're supposed to access it. It probably has a method like getBaseurl that allows you to do so.

Andere Tipps

Assuming, its basecamp-php-api you're using, Basecamp class has a getBaseurl() method with which the base URL is retrievable.

If it's not, you could extend the Basecamp class like this in order to access protected members:

class MyBasecamp extends Basecamp {
   public function getBaseurl() {
      return $this->baseurl;
   }
}

You cannot get value of baseurl property of BaseCamp object outside of it, because it is protected. You need to use some getter method.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top