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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:24:48+00:00 2026-06-17T16:24:48+00:00

From the php manual Include_once may help avoid problems such as function redefinitions, variable

  • 0

From the php manual

Include_once may help avoid problems such as function redefinitions, variable value reassignments, etc.

Ok, so include_once solves issues with function redefinitions, variable value reassignments, etc. but why are they an issue in the first place ?

I’m trying to understand what kind of risks are involved in redefining functions or reassigning variable values except for a decline in performance due to additional input/output and processing ?

Is it because php parser gets confused which version of function to load/use or is the original version of the function lost once redefined? What else and what about variable reassignments?

I do understand where to use include vs include_once.

  • 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-17T16:24:50+00:00Added an answer on June 17, 2026 at 4:24 pm

    Imagine the following include file, hello.php:

    function hello()
    {
        return 'Hello World';
    }
    
    $a = 0;
    

    Now imagine the following file, index.php:

    include 'hello.php';
    
    $a = 1;
    hello();
    
    include 'hello.php';
    
    hello();
    echo $a; // $a = 0, not 1
    

    Your code would now have a fatal error, since the function has been defined twice. Using include_once would avert this, since it would only include hello.php once. Also, to do with variable value reassignment, $a (should the code compile) would be reset to 0.


    From the comments, please consider this a side answer – If you’re looking for something where resetting a set of variables many times was required, I’d look to use a class for this with a method like Reset, you can even make it static if you didn’t want to have to instantiate it, like so:

    public class MyVariables
    {
        public static $MyVariable = "Hello";
        public static $AnotherVariable = 5;
    
        public static function Reset()
        {
            self::$MyVariable = "Hello";
            self::$AnotherVariable = 5;
        }
    }
    

    Usage like:

    MyVariables::$MyVariable = "Goodbye";
    MyVariables::Reset();
    echo MyVariables::$MyVariable; // Hello
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this example from http://www.php.net/manual/ru/function.spl-autoload.php#92767 But this causes an error *Fatal error: spl_autoload()
From perusing the comments at http://php.net/manual/en/function.set-include-path.php , it seems to me that '.', or
Given this example taken from http://php.net/manual/en/function.crypt.php crypt('rasmuslerdorf', '$2a$07$usesomesillystringforsalt$') Firstly: What is the length that
I have the following piece of code taken from the PHP manual on the
I read the manual from the php homepage It writes: // this doesn't go
Anonymous functions are available from PHP 5.3 . Should I use them or avoid
This is from the php manual: http://us.php.net/manual/en/language.constants.syntax.php If you use an undefined constant, PHP
The example from the PHP manual is using OOP. Is there a way to
I have the following test case: include_once('../Logger.php'); class LoggerTest extends PHPUnit_Framework_TestCase { public function
From the PHP manual, session.gc_probability and session.gc_divisor state that gc will occur based on

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.