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 909131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:49:38+00:00 2026-05-15T16:49:38+00:00

I am currently working on a PHP project which includes extensive database usage. The

  • 0

I am currently working on a PHP project which includes extensive database usage. The basics are: I have a PDOFactory class which follows the Factory pattern and an abstract SQL class with static methods (just a container for those methods) which in turn talks to PDOFactory

As I said, the project involves extensive database usage, so the SQL class will contain numerous methods. However, they could be easily grouped, depending on what they deal with (i.e. session storage, user logging on/off, etc.). That would make the SQL class much easier to maintain and so on and forth. And here comes the big question: Can I have the source of the class contents spread across many files? There could be (at least) two possible solutions to this problem:

  • Multiple inheritance, i.e. having classes SQLSession, SQLUser, SQLblahblah and making the SQL class inherit all of them.
  • C++-like pre-processor* directives, i.e. #include SQLSession.php; or something like that.

I know there is no multiple inheritance in PHP, so that rules out option No. 1. Is option No. 2 even possible? Or does anybody know of better solutions to this problem?

*Or actually pre-pre-processor directives, since PHP is a pre-processor. 🙂

EDIT:

Here’s an attempt to answer this question, based on Kalium’s suggestion. It’s a mess to read, but it works. However, I’m gonna stick with Bill’s method as it’s way cleaner.

class SQL {

  private static $oInstance = false;
  public static function getInstance()
  {
    if( self::$oInstance == false )
    {
      self::$oInstance = new self();
    }
    return self::$oInstance;
  }

  public $SESSION;

  private function __construct()
  {
    $this->SESSION = new SESSION;
  }
}

// this would be in another file
class SESSION {
  public function printOne()
  {
    echo "One";
  }
}


SQL::getInstance()->SESSION->printOne(); // outputs "One"

?>
  • 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-15T16:49:39+00:00Added an answer on May 15, 2026 at 4:49 pm

    I think you may be approaching this wrong. That’s certainly not the best way to go about it. Try breaking the many functions into smaller utility classes and then using those to composite a larger class.

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

Sidebar

Related Questions

I am currently working on a php/javascript project which retrieves information from a database
I'm currently working on an OO PHP application. I have a class called validation
On a current project which I'm currently working, i have a symfony task that
I am currently working on a fun project, which involves Ajax, HTML, JavaScript, PHP
I am currently working on a PHP project with MySQL. I have the PHP
I'm currently working on a large project which is expected to have a large
In the project my team is currently working on, we're modifying a commercial PHP
We currently have a working php mail script, this works fine and as we
I'm currently working on a PHP application that uses a MySQL database for its
In a project I'm currently working for, we're considering putting system() into php.ini's disable_functions

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.