0

enter image description here

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?

1
  • The API likely offers a way to specifically access that protected string. A method such as $charge->getStatus(); for instance. Commented Dec 24, 2015 at 7:07

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

I understood that but API returns all of them are protected, not sure how to access them.
in case you have access to documentation, they might have function to get status. Pleas check on it.
0

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);

1 Comment

its not json new guy,
0
<?php

$data = array(
    '_status:protected' => 'Authorized'
);
$arr = (object)$data;
// print_r($arr);
$key = '_status:protected';
echo $arr->$key;
?>

I think this will help you..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.