OOP , new objects and existing objects

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Gurzi
Forum Commoner
Posts: 27
Joined: Wed Aug 02, 2006 4:04 pm

OOP , new objects and existing objects

Post by Gurzi »

Hello folks,

I'm learning how to use OOP , and i already know a little bit of how to use them.
But a question remains in my head, It's supposed to retrieve data from the database and put within the object ?

For example, i have a object User that can make some methods like


makeRequest() to request some file and some other methods.


But my user has attributes like name, age etc.

If it's an existing user, you can download the data from the database and put within the attributes of the object.
But the problem arises when we talk of new users. Shall i create only a constructor to receive da data of the new user as arguments and insert in the database ? Because, for me there isn't any sense to create a object user just to add the user to the database.

Thanks
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: OOP , new objects and existing objects

Post by josh »

That is one way. You could put an SQL query in the constructor that populates the object properties with database fields, after a while if you want to work smarter you will create abstract classes that can generate a range of queries for you. There's lots of ORM frameworks that will save you months of research & development
Post Reply