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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:26:34+00:00 2026-05-30T08:26:34+00:00

I have two classes that I use to access two different tables in my

  • 0

I have two classes that I use to access two different tables in my db. They both have a similar constructor that looks like that:

function __construct($db) {
    $this->db = $db;
    $userDAO = DAO_DBrecord::createUserDAO($this->db);
    $this->userDAO = $userDAO;
}

The other class has the same constructor except that it uses createOtherTableDAO($this->db).

I am planning on having a couple other such classes, and it would be convenient if I could have them all inherit the same constructor, and pass createAppropriateTableDAO as an argument.

To clarify, in the first case above, createUserDAO($this->db) is a static function that calls a constructor in my DAO class. The function in the DAO looks as follows:

public static function createUserDAO($db) {
    return new DAO_DBrecord($db, 'users');
}

I use this method to make sure the user model can only call a DAO on the users table.

I’m somewhat of a beginner, and I don’t think I have ever seen anything like what I want.

  • 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-30T08:26:35+00:00Added an answer on May 30, 2026 at 8:26 am

    To answer your question first: No, you can’t (without resorting to evilCode) pass a function name as a parameter.
    But: What you want to archive is a poster-child-issue for an object oriented approach using inheritance.

    You’d need a base-class:

    class BaseClass
    {    
        function __construct($db) {
            $this->db = db;
        }    
    }
    

    and your implementations :

    class MyClass extends BaseClass
    {
        function __construct($db) {
            parent::__contruct($db);
            $this->userDAO = DAO_DBrecord::createUserDAO($this->db);
        }
    }
    

    Just for the record: the evilCode would have been
    a) you could encapsulate your function in a create_function that can be used as an argument.
    b) you could pass the function name as a string to your function and then pass it to eval in the receiving function.

    But remember: When eval or create_function looks like the answer you’re probably asking the wrong questions!

    See: related question

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

Sidebar

Related Questions

I have two classes that each need an instance of each other to function.
I have two classes that I would like to merge into a composite. These
Suppose I have two classes that both contain a static variable, XmlTag. The second
I'm having trouble grasping generic methods. I have two classes that are generated (they
I have two classes, Foo and Bar, that have constructors like this: class Foo
So i have two classes that are independent of eachother, but both are related
I have two classes, A and Bar, both share a header file that has
I have two classes that refer to each other, but obviously the compiler complains.
I have two classes that I am testing (let's call them ClassA and ClassB).
What I'm talking about here are nested classes. Essentially, I have two classes that

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.