I am trying to leverage my knowledge of OOP to PHP, but I'm new to PHP, so I'm not sure if the following idea is realistic:
If I have a page that updates itself constantly (via AJAX) with data from other users who are on the same page, does it make sense to build a bunch of objects from a Database in order to work on those objects?
For example, let's say I am trying to allow users to play a game, so each action has to be propagated to all other users. This is done via AJAX polling. So every 3 seconds, the page polls for data. (i.e. index.php?user=fish&gameId=456) I was thinking about taking the user and gameIds, creating a Player object, populating the Player object with data from a database, and then performing some routines, such as Player->movePiece(). Thus, every single time a request comes in, one or more objects are instantiated, some functionality is performed, and when the request completes, the objects are destroyed.
Can anyone with experience speak to whether this is a good idea?
[Question] for Experienced OOP PHP Devs
Moderator: General Moderators
-
fish123456
- Forum Newbie
- Posts: 3
- Joined: Thu May 17, 2007 9:30 am
-
fish123456
- Forum Newbie
- Posts: 3
- Joined: Thu May 17, 2007 9:30 am
Thanks for the pointer.Begby wrote:Use OOP in PHP to organize your code and make it easier to maintain/read. Don't worry about instantiating objects and then breaking them back down on each request, its just the way it is with PHP. The performance hit will not be that big of a deal so don't try and optimize the app too early.