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

  • SEARCH
  • Home
  • 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 7878803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:45:49+00:00 2026-06-03T03:45:49+00:00

Just a quick question regarding re-useable code. Ive lately been trying to modularise my

  • 0

Just a quick question regarding re-useable code.

Ive lately been trying to modularise my code. I’m not really good with OO PHP yet (im working towards getting my head around it all) but even if i started using OOP there are a number of scenarios like the one below, where i see an issue with abstracting my code.

So lets say i have a list of users that have posted a comment in a news article. When i get the list of the comments, all i have is the user id. Before i started trying to abstract functionaility, i would have just done something like

SELECT c.*, u.username FROM comments AS c LEFT JOIN users AS u ON c.uid = u.id WHERE c.news_id = 90

This would give me the comment along with the username of who posted it. Now in order to abstract out the retrival of the username (lets say if the username was null, i may want to return the concat of fname and sname) i could do something like this. (bare in mind its an example, i know in most cases username would be a required registration field, imagine im building a base system for developing new sites where the username could be something other than a string in the database).

function getUsername($uid) {
  return /** the username from the database however i decide to get it **/
}

That would have to run at least 1 mysql query. If i have 100 comments on display, that could be 100 queries being run

In OOP i guess i would do something like

$user = new User($uid);
echo $user->getUsername();

But that would also require a query to load the user (and probably be slightly more resource intensive as a user class would get far more information on init to build the user object for all the possible methods to follow.

I know i could use memcache or something to speed things up. Even cache the results so subsequent getUsername() calls with the same uid doesnt require another query. But ni cant think of a solution that comes anywhere near to being as good as getting the username in my usual way (first code snippet).

Am i looking too deep into function abstraction and trying to over use OOP? I dont think so personally, I think its a perfectly valid requirement, and it would make sense to instantiate a user object if i were to be using OOP?

Just looking for some pointers really. Will abstraction functionaility always impact performance? Or am i just going about it the wrong way ?

  • 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-06-03T03:45:53+00:00Added an answer on June 3, 2026 at 3:45 am

    Whilst cleaning up my account i thought it best to close some old questions. What i found is pretty obvious and i had a feeling i knew it all along. For anyone else that is wondering the same as i was and find’s this post. The basic premise is it’s your decision.

    Basically you can fully abstract your methods so their completely standalone and suffer some pretty major performance issues, or at the other end of the scale you can not abstract at all and be able to tweak every little thing to get the best performance. Performance and abstraction in a general sense opposite’s, so find somewhere in the middle that makes you happy.

    In the case above i decided to make the method static then pass in either a user id, or an array. The code then checks if its an array or integer, if its an integer or if the array doesn’t contain the required keys, it does a query lookup before generating a username for return.

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

Sidebar

Related Questions

just a quick question regarding C and processes. In my program, I create another
I just had a quick question regarding loops in Ruby. Is there a difference
I have a quick question regarding memory management that I am not quite sure
I just have a quick best practice question regarding custom cells in a UITableView.
Quick question regarding EventHandlers in C#, let's say we have the following code: MyObject.MyEventHandler
Hi guys just a quick question, After having a nightmare trying to get an
Just a quick question regarding the split function How can I split my string
I have got just a quick question regarding the header hierarchy when using HTML5
Just a quick question regarding Junction tables in Oracle SQL. I understand their functionality
Just a quick question. If I learn how to develop apps for IPhone using

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.