カテゴリー:
Stripe
閲覧数:327 配信日:2019-03-11 09:58
質問履歴18-1
Tell me why I can also access as an array as an object
・2019/3/7
Create a Stripe Product object.
\Stripe\Stripe::setApiKey("sk_test_××××××");
$product = \Stripe\Product::create([
'name' => 'My SaaS Platform',
'type' => 'service',
]);
Get the id of the Product object
echo $product->id;
· I can understand the above codeecho $product['id'];
· I can not understand the above code・What is the reason why the returned value should be an object but can be accessed in an array?
A.18-1
implements ArrayAccess
・「ArrayAccessインターフェースをimplementsしているオブジェクト」だから、配列形式でもアクセスできる
・Product extends ApiResource which extends StripeObject which implements ArrayAccess.