创建数组时出错:class stdClass 的对象无法转换为字符串

error when creating an array: Object of class stdClass could not be converted to string

我正在使用标签创建数组并在数组内创建数组,当 Laravel 6.2 给我这个错误时:

class stdClass 的对象无法转换为字符串

这不是语法错误。

[
'product_id'=>(string)$productId,
'name'=>
'SubscriptionPlan',
'description'=>
'SubscriptionPlan',
'status'=>'ACTIVE',
'billing_cycles'=>[
0=>[
'frequency'=>[
'interval_unit'=>'MONTH',
'interval_count'=>1,
],
'tenure_type'=>'REGULAR',
'sequence'=>2,
'total_cycles'=>999,
'pricing_scheme'=>[
'fixed_price'=>[
'value'=>(string)$p->monthlyFee,
'currency_code'=>'USD',
],
],
],
],
'payment_preferences'=>[
'auto_bill_outstanding'=>true,
'setup_fee'=>[
'value'=>'0',
'currency_code'=>'USD',
],
'setup_fee_failure_action'=>'CONTINUE',
'payment_failure_threshold'=>3,
],
'taxes'=>[
'percentage'=>'10',
'inclusive'=>false,
],
];

您正在将两个变量转换为字符串:

  • $productId
  • $p->月费

其中一个是对象。 您不能以这种方式将对象转换为字符串。 您应该尝试转储这两个变量,看看是哪一个是问题的原因。

新年快乐!