It is difficult to say without further details. You would have to see the implementation of this, how it will be used and what might happen in the future to make the decision. I don’t even know if I should receive an object User
.
If that’s what you want to do, do it, and see if that’s good in the future. And maybe you’ll find something else that a lot of people don’t realize: people do things for easier maintenance later, and they take the time to do that, and maintenance never comes. What I see most nowadays is a system that is virtually undeveloped, so you adopt a complexity for something that is not used.
OOP
But the first thing you should know is that there are several definitions of what object orientation is. And in all PHP benefits very little from this paradigm because it is secondary (some say not even a paradigm at all), because it serves to organize complex codes that relate in a complex way. PHP is a language of script, It’s practically an inherent microservice. It separates things so much that it makes little sense to use OOP in it. But she started to allow it because the industry in general is little informed of how things work and are very guided by marketing, which made her adopt the possibility of writing code like this "not to be out of fashion".
It makes more sense to use OOP in Hack, Java or C#.
But I can say that there is no magic formula to define what is right to respect OOP. And if you do, why do you need to respect if you do something that is appropriate to what you need? What problem does this cause? You have to make the decision because some problem is caused if you do it wrong. If you can’t define if it causes any problems, it’s not because it’s OOP that will help.
Among these controversies about what is OOP there are those who say that everything that concerns the object must be inside it, that is encapsulation. But each one has a vision of what this is all about. There are those who say that if something can be left out then it should be. I am in this class. That is, nothing to encapsulate the whole, but encapsulate the minimum. To such an extent that in some cases it should not even have a class. Much less with all the mechanisms they use.
Whatever the option, without mastering how to model things, without much experience, without having all the necessary information on the subject, and usually you don’t have that, unless you’re doing something you’ve done before and learned a lot from it, potentially you’ll get it wrong.
Learn to model and worry less about OOP. Even because they started using the term for two or more different things, there when you’re reading something you don’t know which version of OOP they’re talking to. And of course, whoever is saying that says that his is OOP, the rest is something else. Much of what they say is OOP is just modularization.
I realize that people have difficulty respecting even grammatical issues in Portuguese that they use all the time (I myself am like this), imagine in something that she does not always use, because the language that a person should speak when programming is the problem to be solved, It’s not even the programming language. People go through a lot of trouble on taxonomy and ontology or even dialectics, so it’s hard to get it right and know that you’re right.
And out comes this:
Or even worse in OOP it happens a lot (and they don’t notice, especially in PHP):
Concepts that should be mastered and that have nothing (directly) to do with OOP: What are the concepts of cohesion and coupling?.
And see Is it correct to say that encapsulation aims at cohesion? Why?.
In my view, the biggest problem is to pass an entire object if the only thing you need is a number (id). I suggest reading that one question first
– Costamilam