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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:12:22+00:00 2026-05-13T11:12:22+00:00

First of all, I do not want to extend a class. I would ideally

  • 0

First of all, I do not want to extend a class. I would ideally like to do this.

public function __construct() {
 /* Set Framework Variable */
 global $Five;
 $this =& $Five;
}

I have a system where the variable $Five is a container class which contains other libraries. I could assign this to a local variable of Five… i.e.

public function __construct() {
 /* Set Framework Variable */
 global $Five;
 $this->Five = $Five;
}

However, the reason why I am trying to avoid this is that function calls would be getting a little long.

$this->Five->load->library('library_name');

Its a little ugly. Far better would be.

$this->load->library('library_name');

What is the best solution for this?

  • 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-13T11:12:22+00:00Added an answer on May 13, 2026 at 11:12 am

    I think that

    $this->Five->load->library('library_name');
    

    is going to be your best option unless you decide to have the class extend the helper class. AKA

    class Something extends Helper_Class
    

    However, this means that Helper_Class is instantiated every time you instantiate a class.


    Another method would be to have a pseudo-static class that assigned all of the helper classes to class members

    public function setGlobals($five)
    {
        $this->loader = $five->loader;
    }
    

    Then just call it

    public function __construct($five)
    {
        someClass::setGlobals($five);
    }
    

    If $Five is a global, you could just global $Five everytime you want to use it, but putting that at the top of every function just seems like bad coding.


    Also, I’d just like to do my public service announcement that Global variables are generally a bad idea, and you might want to search ‘Dependency Injection’ or alternative to globals. AKA

    public function __construct($five);
    

    instead of

    global $five;
    

    Globals rely on an outside variable to be present and already set, while dependency injection requests a variable that it is assuming to be an instance of the Five class.

    If you are running PHP 5.1 (Thanks Gordon), you can insure the variable is an instance of the FiveClass by doing this:

    public function__construct(FiveClass $five);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to manage all activities with class conductor like this: Also all activities
First of all, I want to be clear that I'm not talking about defining
first of all: this is not the same as this . The ModelBackend has
First of all I'm not sure this is even possible, however I need to
First of all I am not a designer. so this question is may be
First of all: This question is not directly programming related. However, the problem only
I want to write an extend of the class SSLCertificateSocketFactory . First I search
First of all: I am not able to find out the proper Title of
First of all I'm not sure if .exe window is the proper term. It's
first of all I'm really not really friendly with ruby or with rails, so

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.