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

45 Views Asked by At

I was creating an array using labels and creating arrays inside arrays, when Laravel 6.2 gave me this error:

Object of class stdClass could not be converted to string

It's not syntax error.

[
'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,
],
];
1

There are 1 best solutions below

2
Mathieu Tristan On BEST ANSWER

You're casting two variable to string:

  • $productId
  • $p->monthlyFee

One of them is an object. You can't cast object to string this way. You should try to dump both variables to see which one is the cause of the problem.

Happy new year !