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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:26:14+00:00 2026-06-09T19:26:14+00:00

I had a file test.php with the following code <?php //name of this file

  • 0

I had a file test.php with the following code

<?php
//name of this file is test.php
$foo = "some value";
include_once 'extras.php';
$bar = "another value";
echo "test.php: foo is $foo and bar is $bar <br />";
?>

Another file with the code

<?php
echo "extras.php: foo is $foo and bar is $bar <br />";
?>

The output indicates that echo statement from extras.php is included as well in test.php, whereas I being a newbie was assuming that include_once or include constructs only deal with the variables and functions and disregard other stuff. What is correct, guide please.
Thank you

  • 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-06-09T19:26:15+00:00Added an answer on June 9, 2026 at 7:26 pm

    include_once includes the entirety of the script into the calling script, so long as it hasn’t been previously included. This includes all variables, functions, echos…everything. In effect, the code is imported into the space where the include_once line is, so it is possible to reference variables of an includeded script in the calling script.

    The script you posted looks like this, after the includes are processed:

    <?php
    //name of this file is test.php
    $foo = "some value";
    echo "extras.php: foo is $foo and bar is $bar <br />";
    $bar = "another value";
    echo "test.php: foo is $foo and bar is $bar <br />";
    ?>
    

    Just be aware that if the file isn’t found, the script doesn’t error out, but variables set up in the included script won’t be set. For that, use require_once.

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

Sidebar

Related Questions

If in a php file you had: $smarty->assign('content','<p>This is some test content</p>'); and in
If I had to following file on my development branch: # file.rb class Code
I have the following code in a PHP file called via Ajax (note -
I had a huge file for creating this GUI and I have shortened it
I had created a zip file (together with directory) under Windows as follow (Code
I've not had to write much batch file code in the past and I'm
I am getting the form on click from a file called test.php which contains
This is probably an easy one for some of you. I'm trying to test
I had some JavaScript code which was working but when I tried to put
I provide this directory & file: $path = $_POST['q2Path']; $file = test.txt; // q2Path

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.