Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3312220
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:58:09+00:00 2026-05-17T21:58:09+00:00

I was asked to do a project in PHP and to make sure it

  • 0

I was asked to do a project in PHP and to make sure it was object oriented. I’ve done OO and I’ve done PHP, but never both.

The main benefit of OO PHP (outside of inheritance/polymorphism) seems to be code organization. That’s fine; I’m doing that. But where I get stuck is if I should actually be creating instances for every “object.”

To me (and maybe I’m being naive here), a web app is all about making very short, stateless requests to alter or retrieve records in a database. The objects can’t persist between requests. So it feels rather pointless to load data from the database, construct an object from that data, make a small update, save the data from the object back to the database, and then throw the object away. The loading/saving code seems to be a lot of work for nothing. [clarification: a waste of development time, not processing time… not too concerned about overhead]

The alternative is to have a bunch of singletons (or classes with static methods) that just provide a nice, organized abstraction layer to the database layer. I guess writing code in this manner just doesn’t feel truly OO. Am I missing something or is that style fine?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:58:09+00:00Added an answer on May 17, 2026 at 9:58 pm

    Singletons are essentially just global variables with some namespace sugar added in. There are a few main benefits to programming with objects and classes that you just don’t get from straight procedural programming. One is inheritance, as you mentioned. Another is the namespacing – you can have a code to compress the lot into a single include file (more meaningful in interpreted languages like PHP than in compiled languages).

    Objects are essentially a collection of functions with a shared state (though singletons make that a global state. Beware.) As you pointed out the benefit is mostly that that state is transparently shared by the functions without needing to explicitly pass it every single call. If you have various functions per request operating on shared data and wish them to be specialized forms of a general set of functions, OOP is probably a good fit.

    Since you have been tasked to “make sure it is object oriented”, I’d take some time to consider common groups of functions, generalizations of same, etc.

    In the end the setup/teardown time of the objects isn’t too bad – and it might even save some development time in the future if you do a good job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked a somewhat related question but I want it to make it more
I have been asked to do a project where the client can create PHP
I'm starting a new project using Linux and PHP, but for the early dev
The question has been asked: No PHP for large projects? Why not? It's a
I was asked to manage and develop a project. The client does not really
I've been asked to help out on an XNA project with the AI. I'm
I have been asked to lend a hand on a hobby project that a
Despite an earlier question ( asked here ), our project is constrained to using
(I asked this question in another way , and got some interesting responses but
I've been asked by a client to make an online tracking system for work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.