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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:00:52+00:00 2026-05-23T18:00:52+00:00

Ok so i have the following code setup which seems to work fine: user

  • 0

Ok so i have the following code setup which seems to work fine:

user handler “module”:

class user_handler
{
    private $dbo;

    public function __construct($dbo)
    {
        $this->dbo = $dbo;
    }

    public function user_table_method()
    {
        $this->dbo->generic_db_method();
    }
}

the connection class:

class connection
{
    private $dbc;

    public $user;

    public function __construct()
    {
        $this->dbc = 'connection';
        $this->user = new user_handler($this);
    }

    public function generic_db_method()
    {
        echo '<p>doing stuff with ' . $this->dbc . '</p>';
    }
}

Then i can access user handler methods like so:

$dbc = new connection();
$dbc->user->user_table_method();

My question is this:

Would it be possible with a method in the connection class to create the _user object only when it’s required?

What i’m thinking of is a method that would be used like so:

$dbc->add_handle('user', 'user_handler');

Which would create a new public property called user from scratch and set it as a new
user_handler object:

// in more detail
public function add_handle($name, $module)
{
    if(!isset($this->/*somehow use $name*/))
    {
        $this->/*somehow use $name*/ = new /*somehow use $module*/();
    }
}

..so the new way to set it up would be like:

$dbc = new connection();
$dbc->add_handle('user', 'user_handler');
$dbc->user->user_table_method();

Thanks in advance! (looking at php 5.2 and up)

  • 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-23T18:00:53+00:00Added an answer on May 23, 2026 at 6:00 pm
    public function add_handle($name, $module)
    {
        if(!isset($this->$name))
        {
            $this->$name = new $module();
        }
    }
    

    Then you would just do similar to how you were thinking:

    $dbc = new connection();
    $name = 'user';
    $module = 'somemodule';
    $dbc->add_handle($name, $module);
    $dbc->user->user_table_method();
    

    I’ve also renamed it from $_user to $user as I mentioned in the comment since it is public.

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

Sidebar

Related Questions

I have following code class User attr_accessor :name end u = User.new u.name =
I have the following jQuery code which I like to convert to work with
I have the following setup: Code on my local machine (OS X) shared as
I have the following piece of code: // setup the AJAX request var pageRequest
I have following Code Block Which I tried to optimize in the Optimized section
I have code similar to the following: public class myButton extends JButton() { public
I have the following code set up in my Startup IDictionary<string, string> properties =
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My

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.