W
W
webquestions2016-01-20 11:25:49
PHP
webquestions, 2016-01-20 11:25:49

When to use methods when php objects?

I have a method, for example, to display lists of news, we pass the category ID to the method parameter, in different sections there are different categories, as for me everything is fine and correct, but maybe I'm wrong. Throughout the work, I practically did not use objects, where is their use justified? If possible with an accessible example

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-01-20
Protko @Fesor

where is their use justified?

Be guided by common sense. In general, there is such a practice when in general everything turns into objects, especially entity IDs. But this is an overhead in the vast majority of cases. They do this to distinguish IDs of different entities, for example. Type CategoryId and ArticleId, and if there is no profit in this for you, you can just use scalars for IDs.
Business objects are better described by an object, so we will know the structure of the object, we can track the type of the object, etc. This reduces the chance of errors.
In general, in PHP, you can conveniently use only OO approaches (when building application architecture, this does not mean that we cannot apply the ideas of functional programming, and do not confuse this with a procedural approach), because it all comes down to simple things like encapsulation, polymorphism, principles SOLID and GRASP. By default, everything must be objects and everything must have a type. Further, it can already be simplified depending on the requirements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question