I am trying to integrate an API and its response is saved in $charge variable. I tried to access this via $charge->_status:protected but fail. How to access those variables?
4 Answers
gIn your case it's just
$charge->getStatus();
The way you ask the question shows you've got a little misunderstanding. The property name is "_status" and it's visibility is protected.
This is why the print_r output has it as "_status:protected" but that is not the property name, but an informative encoding.
Protected visibility means, that you can not access it via the class public interface. The module designer has added the public property method getStatus() (a so called "getter" method) so that it is accessible for reading.
You can find the method definition in the source-code here: https://github.com/CKOTech/checkout-php-library/blob/master/com/checkout/ApiServices/Charges/ResponseModels/Charge.php#L269
Comments
Try as
$charge->_status
Based on the given image it seems that the _status is declared as protected and it won't allow you to access outside the class.
2 Comments
try this json response is in a variable named $charge, you must use json_decode and then do as like this example:
$decoded = json_decode($charge);
$result = $decoded->result;
$quote = $decoded->info->quote;
var_dump($result, $quote);

$charge->getStatus();for instance.