Usefulness of loading instances in OO PHP?

I was asked to make a project in PHP and make sure that it is object oriented. I did OO and I did PHP, but not both.

The main advantage of OO PHP (outside of inheritance / polymorphism), apparently, is the organization of the code. It's great; I'm doing it. But where am I stuck if I really have to instantiate each "object".

For me (and maybe I'm naive here), the web application is connected with very short stateless requests to modify or retrieve records in the database. Objects cannot be saved between requests. Therefore, it is useless to load data from a database, build an object from this data, do a small update, save data from the object back to the database, and then discard the object. Load / save codes seem to work a lot for nothing. [clarification: a waste of development time, not processing time ... not too concerned about overhead)

An alternative is to have multiple singletones (or classes with static methods) that simply provide a good, organized level of abstraction for the database level. I think writing code this way just doesn't really feel like OO. Am I missing something or is this style great?

+3
source share
4 answers

- , , . , . - , . - include ( , PHP, ).

- , , ( . .) , , . , , , , , , .

", -", , ..

, / - , .

+2

, OO " "; ( PHP). , ; , , .. , , (, , ..) , (). , .

, - .

, , ", OO". . , , , ...

+6

, - . , (, MVC).

: Fat-Free.

, . , (Caching, ORM, CRUD, Captcha...) , .

. , PHP 5.3. , , . ; .

+2

, - .

ORM (, php) , ( ), , , , , ,...

, , , - .

+1

Source: https://habr.com/ru/post/1772953/


All Articles