使用PHP访问对象变量

时间:2013-04-19 18:06:04

标签: php object

在PHP中访问对象中的变量的正确方法是什么?这些似乎不起作用。

$response = $wepay->request('checkout/create', array(
    'account_id'        => $account_id,
    'amount'            => '24.95',
    'short_description' => 'A brand new soccer ball',
    'type'              => 'GOODS',
    'mode'              => 'regular'


));

// display the response
print_r($response);
//prints stdClass Object ( [checkout_id] => 466761864 [checkout_uri] => https://stage.wepay.com/api/checkout/466761864/6c60270d )

echo $response[checkout_id]; //nothing
echo $response->$checkout_id; //nothing
var_dump(get_object_vars($response));  //nothing

我只需要从$ response获取[checkout_id]和[checkout_uri]。 我是php对象的新手,但是从环顾四周来看,这些都是人们所说的方式,他们只是在这种情况下不工作。对不起,如果这很简单。

1 个答案:

答案 0 :(得分:5)

使用->运算符访问对象属性时,属性名称不得以$为前缀。

这对你有用:

echo $response->checkout_id;

您可以关注manual

相关问题