I am having problems getting the php 'foreach' to work with a Stripe object.
i can run the following command which gives me expected results:
error_log(gettype($event->data->object->metadata)); // displays 'Stripe\StripeObject Object'
then i can run this:
error_log(print_r($event->data->object->metadata, true));
which displays:
(
[last_name] => XXXXX
[gateway_id] => stripe_cc
[user_agent] => Mozilla/5.0 . . . . . . .Chrome/141.0.0.0 Safari/537.36
[webhook_id] => we_XZXXXXd0n
[first_name] => XXX
.......................
[ip_address] => 123.123.123.123
)
and i can even extract values using something like this:
$event->data->object->metadata['ip_address'] // returns ip address
$event->data->object->metadata['first_name'] // returns first name
however, for whatever reason, i cannot seem to get the following foreach statements to produce anything:
foreach ($event->data->object->metadata as $key => $value ) {
error_log( $key . ' => ' $value );
}
foreach ( (array) $event->data->object->metadata as $key => $value ) {
error_log( $key . ' => ' $value );
}
foreach ( get_object_vars($event->data->object['metadata']) as $key => $value) {
error_log( $key . ' => ' $value );
}
is there something glaringly obvious i am missing?
ArrayAccessprotocol, which allows indexing them. But they're not really arrays, so you can't use all array operations likeforeach.foreachover the public properties of a PHP class in general (3v4l.org/fKXB1) so it's a bit unclear (to me at least) why the properties of this particular StripeObect class would be any different? What have I missed?Iterableinterface.var_dump()distinguishes them, I couldn't remember ifprint_r()does (I hadn't looked at your demo).