How to access protected property in a class?

Hello,

I am using this class to communicate with MessageBird.

class Sms {
  public function send_verification($number)
  {
    global $MessageBird, $db;
    $Verify = new \MessageBird\Objects\Verify();
    $Verify->recipient = $number;

    $VerifyResult = $MessageBird->verify->create($Verify);

    return $VerifyResult;
  }
}

This will return the following Object:

MessageBird\Objects\Verify Object
(
    [id:protected] => 8e863bf2556d5bffbe63435v09993219
    [recipient] => 4915142356308
)

How can I access the protected id within the class?
I would like to add the id to my database.
I tried $VerifyResult->id; to access but this does not work.

Reflection can sometimes be your friend. Use sparingly. http://php.net/manual/en/reflectionclass.getproperty.php

1 Like

How to use reflectionclass with an namespace class like \MessageBird\Objects\Verify()?

There is probably a public or magical accessor method on that object. Use reflection as a LAST resort.

Post what you have tried and Iā€™m sure someone will be glad to help.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.