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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:27:11+00:00 2026-05-17T17:27:11+00:00

If I have: require_once(bla.php); class controller{…..} If I then create in a different file

  • 0

If I have:

require_once("bla.php");
class controller{.....}

If I then create in a different file class control_A extends controller{...}, do I need to again say require_once("bla.php");, or is it inherited?

What if the require_once is done inside the class controller definition?

  • 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-17T17:27:12+00:00Added an answer on May 17, 2026 at 5:27 pm

    So far we have two contradicting, but equally correct answers =) Let’s see if I can’t combine the two into a more specific total answer.

    If any class requires any code or definitions in bla.php, then you will need to include("bla.php") at least one time in the entire run-time of your script. If your previous code:

    require_once("bla.php");
    class controller{.....}
    

    is in the file controller.php then you can create control_A in the following way:

    require_once("controller.php");
    class control_A extends controller{...}
    

    This is because the require_once() function essentially copies and pastes the contents of the file into the script at that line. Therefore the above will be seen equivalent to this:

    /* INSERTED FROM controller.php */
    /* INSERTED FROM bla.php */
    necessary definitions for controller
    /* END bla.php */
    class controller{.....}
    /* END controller.php */
    class control_A extends controller{...}
    

    As you can see, just by requiring controller.php, the necessary definitions for controller are now seen and parsed. What you can not do is omit the declaration of controller. This isn’t just because you required bla.php while declaring it, but also you can’t extend a class which hasn’t yet been declared. So the following code:

    class control_A extends controller{...}
    

    will give you an error since controller hasn’t been defined.

    One thing to consider, however- since the class controller doesn’t extend any other class, it should not have any external dependencies. There’s a good chance that whatever you do in bla.php which must run before defining the class is either unnecessary or can be restructured. What exactly is bla.php doing that you need before defining controller?

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

Sidebar

Related Questions

If I have this: require_once('myfile.php'); then later: include_once('myfile.php'); Will the file get included again
I have a file index.php in root directory: <?php require_once ./include/common.php; ?> and file
Consider the following PHP code: <?php require_once(myDBclass.php); class a { private $tablename; private $column;
I have a file I use called fileCabinet.php to load in all my classes
I have a console application that require to use some code that need administrator
I have a unit test (example is modified Test::Unit documentation ) require 'test/unit' class
In our product we have a big utilities file that we require (with do
again. Right now I'm having issues with some pretty basic functionality in PHP. I
I have a command interpreter in php. It lives inside the commands directory and
Once I have all the files I require in a particular folder, I would

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.