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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:55:44+00:00 2026-05-30T18:55:44+00:00

From what I understand using something like require_once will essentially copy and paste the

  • 0

From what I understand using something like require_once will essentially copy and paste the code from one file into another, as if it was in the first file originally.
Meaning if I was to do something like this it would be valid

foo.php

<?php
require_once("bar.php");
?>

bar.php

<?php
print "Hello World!"
?>

running php foo.php will just output "Hello World!"

Now my question is, if I include require_once inside a method, will the file that is included be loaded when the script is loaded, or only when the method is called?.
And if it is only when the method is called, is there any benefit performance wise. Or would it be the same as if I had kept all the code into one big file.

I’m mainly asking as I’ve created an API file, which handles a large amount of calls, and I wan’t to simplify the file. (I know I can do this just be creating separate classes, but I thought this would be good to know)

(Sorry if this has already been asked, I wasn’t sure what to search for)

  • 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-30T18:55:46+00:00Added an answer on May 30, 2026 at 6:55 pm

    1) Only when the method is called.

    2) I would imagine there’s an intangible benefit to loading on the fly so the PHP interpreter doesn’t have to parse extra code if it’s not being used.

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

Sidebar

Related Questions

From the design of Scala's collections I understand that something like: scala> BitSet(1,2,3) map
I am using DBus in a project. I understand from DBus specification that for
Using a delegate I can call any function asynchronously. From the documentation I understand
From what I understand of REST principles, URLs should represent a single resource, like
Did anyone set up something like this for himself using the existing node.js REPL?
I'm looking into speeding up my python code, which is all matrix math, using
I have seen an implementation of Factory using static methods. Something like this: public
I was thinking of creating a chatbot using something like markov chains, but I'm
From what I understand, the parent attribute of a db.Model (typically defined/passed in the
From what I understand, due to the same origin policy enforcement in current browsers,

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.