カテゴリー:
Stripe
閲覧数:318 配信日:2019-03-12 09:41
質問履歴18-2
Is there a way to check whether the object (such as the return value from the API) is implements ArrayAccess?
・2019/3/11
・Is there a way to judge whether it is implements ArrayAccess by return value object without reading the document of API?
\Stripe\Stripe::setApiKey("sk_test_××××××");
$product = \Stripe\Product::create([
'name' => 'My SaaS Platform',
'type' => 'service',
]);
Access by object
echo $product->id;
Access by array
echo $product['id'];
A.18-2
2案
・is_subclass_of
・instanceof
\Stripe\Stripe::setApiKey("sk_test_××××");
$product = \Stripe\Product::create([
'name' => 'My SaaS Platform 2019年3月6日',
'type' => 'good',
]);
if (is_subclass_of($product, 'ArrayAccess')) {
echo "yes, \$product is a implements ArrayAccess\n";
} else {
echo "no, \$product is not implements ArrayAccess\n";
}
var_dump($product instanceof ArrayAccess);
質問履歴18-3
・「あるオブジェクト」が、「指定インターフェース」を「implementsしているかどうか」の条件判定について