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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:50:29+00:00 2026-05-16T16:50:29+00:00

Taking Fabien Potencier’s example : class User { function __construct($storage) { $this->storage = $storage;

  • 0

Taking Fabien Potencier’s example:

class User
{
  function __construct($storage)
  {
    $this->storage = $storage;
  }

  // ...
}

Assuming the Storage class is defined in a different php file (say, storage.php), do I need to include it in this file where the injection is done via a require_once?

Thanks,

JDelage

  • 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-16T16:50:29+00:00Added an answer on May 16, 2026 at 4:50 pm

    You should be putting all your requires and includes at the head of the file – that certainly a style thing, but for one thing it allows you to see by glancing at the source, what other files are need by your PHP file.

    There are two cases:

    1. You will only ever use user.php and storage.php from other files (app.php say)
    2. There are cases where you will use user.php and don’t want to worry about remembering to require storage.php.

    For #1 – you don’t need to worry about requires, however there’s no significant disadvantage to using require_once at the head of your PHP even if most of the time it’ll have already been required.

    For #2 – you need to use require_once at the header since you cannot use user.php without storage.php and the final page only knows it needs user.php.

    short answer: Use require_once to include all dependencies for the code (to allow it to easily be used by other code)

    note: You should only include direct-dependencies for the code. That is: if you have group.php that uses user.php, it should require_once 'user.php', but need not worry about storage.php since it isn’t directly used, and user.php implicitly includes it (that being said – no significant performance disadvantage of being thorough if you wish)

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

Sidebar

Related Questions

Taking the jQuery framework for example, if you run code like this: $(document).ready(function init()
Taking this file as an example, I'm trying to read the data in a
Taking a JavaScript object with 4 properties: function Object() { this.prop1; this.prop2; this.prop3; this.prop4;
Taking this below example : 'user_stats': {'Blog': '1', 'Discussions': '2', 'Followers': '21', 'Following': '21',
Taking this simplifed example of my XML: <?xml version=1.0?> <message xmlns=http://www.mydomain.com/MyDataFeed xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.mydomain.com/MyDataFeed https://secure.mydomain/MyDataFeed/myDataFeed.xsd
Taking the XSLT and XML from this page as an example: http://www.w3schools.com/xsl/xsl_transformation.asp I have
Taking for example this method declaration: const Vector Vector::operator - ( const Vector& other
Taking this basic example of jQuery Validate (see link below), how can you instruct
Taking this thread to the next level and now making a Main.as class to
Taking this article on classes and structs as an example: http://msdn.microsoft.com/en-us/library/ms173109.aspx namespace ProgrammingGuide {

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.