Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FallOutBoi's avatar

Is it okay to use data objects instead of array?

I always displayed data on applications like so

Controller :

$user = User::find($id)->firstOrFail();

View :

<span>$user->name</span>
<span>$user->lname</span>

I was just wondering, is this wrong or unpractical? To use an object instead of array or json or whatever.

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

its preferred.

Objects are a lot more flexible and powerful than arrays.

1 like

Please or to participate in this conversation.