PHP SDK Demystified – Standard Getters and Setters for Protected Properties

An overview on the Facebook class properties was already given in previous articles.

To re-cap, the following class properties are defined in the Facebook class:

  • Static Configuration Related:
    $CURL_OPTS, $DROP_QUERY_PARAMS and $DOMAIN_MAP
  • Runtime Configuration Related:
    $appId, $appSecret, $cookieSupport, $baseDomain, $fileUploadSupport
  • Runtime Status Related:
    $session, $signedRequest, $sessionLoad

Notice that these properties are defined by using keywords “public”, “protected” or “static” added.

For those public static properties (i.e. $CURL_OPTS and $DOMAIN_MAP), we can access them directly without instantiating a class object (i.e. before calling $facebook = new Facebook(array(…..)); ).  This makes sense as the “static configuration” of the PHP SDK should “exist” even when the object is not created.

As an example, the following code will print out the cURL options used in the PHP SDK:

print_r (Facebook::$CURL_OPTS);

For class properties without the keyword “static”, they will be created when the Facebook class object is created.  However, as they are declared as protected, we cannot access them with code like:

$myAppID = $facebook->appId;

Trying to do so will result in PHP fatal error like “Cannot access protected property Facebook::$appId”.

To access (read and set) them, the corresponding getter and setter methods should be used.

  • For $appId:
    getAppId() and setAppId($appId)
  • For $appSecret:
    getApiSecret() and setApiSecret($apiSecret)
  • For $cookieSupport:
    useCookieSupport() and setCookieSupport($cookieSupport)
  • For $baseDomain:
    getBaseDomain() and setBaseDomain($domain)
  • For $fileUploadSupport:
    useFileUploadSupport() and setFileUploadSupport($fileUploadSupport)
  • For $session:
    getSession() and setSession($session=null, $write_cookie=true)
  • For $signedRequest:
    getSignedRequest()
    * There is no setter method as the signed request is to be built by the PHP SDK.
  • For $sessionLoad:
    * There is no getter and setter method as this property used internally only.

Although setter methods are defined, a common way of setting these properties is fact by using the class constructor (i.e. set the values when instantiating the class object).  We will discuss this later.

This entry was posted in PHP SDK Demystified and tagged . Bookmark the permalink.

One Response to PHP SDK Demystified – Standard Getters and Setters for Protected Properties

  1. Hi There,
    A Closer Look at the get Session learn how the PHP SDK will try to build
    Thanks,
    Mick

Leave a Reply

Your email address will not be published. Required fields are marked *