Return object instead of array from shared controller

I need a lot of logic in my controller and am pulling in a shared controller. Once the shared controller returns, I use array syntax to access the info like $shared['data']. I prefer object syntax such as $shared->data but don’t know how to return an object instead of an array from a controller. Is this possible?

I tried the below, but it still returned an array.

#shared-controller.php
...
return (object) [
  'data' => $data,
  ...
]

A controller always returns an array.