Reputation: 9890
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?
Upvotes: 0
Views: 141
Reputation: 198115
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
Upvotes: 2
Reputation: 394
<?php
$data = array(
'_status:protected' => 'Authorized'
);
$arr = (object)$data;
// print_r($arr);
$key = '_status:protected';
echo $arr->$key;
?>
I think this will help you..
Upvotes: 0
Reputation: 1110
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);
Upvotes: 0
Reputation: 1856
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.
Upvotes: 0