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 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

Ask A Question

Stats

  • Questions 532k
  • Answers 532k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No. If you only want to do something when an… May 17, 2026 at 12:16 am
  • Editorial Team
    Editorial Team added an answer Yeah that's safe. If it's stored in the database, there's… May 17, 2026 at 12:16 am
  • Editorial Team
    Editorial Team added an answer Okay I've got it It returns everything after the #.… May 17, 2026 at 12:16 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Taking this article on classes and structs as an example: http://msdn.microsoft.com/en-us/library/ms173109.aspx namespace ProgrammingGuide {
Taking advice from this post , I purchased a copy of 'The C Programming
It's taking me way to long to make this simple form. Almost there but
Thank you for taking the time to read this and I will appreciate every
this program hangs after taking first argument:- #include <stdio.h> #include <conio.h> void ellip(char*,...); int
Thank you for taking the time to read this and I will appreciate every
Thank you for taking the time to read this and I will appreciate every
Taking over some code from my predecessor and I found a query that uses
Taking shs's question a step further... Why isn't all government sponsored software open source?
Taking CPU affinity into account, will such an environment be useful with threading? Or

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.