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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:55:58+00:00 2026-05-24T09:55:58+00:00

Imagine we have 2 files, one called 1.php with the following code: <?php $hello

  • 0

Imagine we have 2 files, one called 1.php with the following code:

<?php
    $hello = "Hello from 1";
?>

and 2.php with the following code:

<?php
    function LoadPage( $page )
    {
        $f = fopen( $page, 'r+' );  
        $content = fread( $f, filesize($page) );
        fclose( $f );
        return $content;
    }

    function GetEvalContent( $content )
    {
        $var = "";
        ob_start();
        eval( "?>" . $content . "<?" );
        $var = ob_get_contents();
        ob_end_clean();
        return $var;
    }

    $hello = "hello from 2";

    echo $hello . '<br/>';

    $content = LoadPage( '1.php' );
    GetEvalContent( $content );

    echo $hello;
?>

So what the 2.php does is load the content of 1.php and evaluate the php code inside it. Now what I want to do is during the evaluation of 1.php, variable $hello changes to “hello from 1”. However if you execute 2.php you always get:

"hello from 2"
"hello from 2"

instead of getting

"hello from 2"
"hello from 1"

Has anyone encountered this problem before and if so, how would you fix it?

  • 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-24T09:55:59+00:00Added an answer on May 24, 2026 at 9:55 am

    There is a much easier way to do this. Use PHP’s include.

    1.php

    <?php
       $hello = "Hello from 1";
    ?>
    

    2.php

    <?php
       $hello = "hello from 2";
       echo $hello;
       include '1.php';
       echo $hello;
    ?>
    

    UPDATE (not tested):

    function includeFile($file){
      global $hello;  // Use the global variable $hello
                      // this will make the include sets $hello correctly
      ob_start();
      include $file;  // Remember any variables set here will be in this scope,
                      // not the global scope (unless you add them to the global line above)
      $var = ob_get_contents();  // This will contain anything echoed to the screen
                                 // from the included file
      ob_end_clean();
      return $var;
    }
    
    $hello = "hello from 2";
    echo $hello;
    $file = '1.php';
    $output = includeFile($file);
    echo $hello;
    echo $output;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have an function which goes through one million/billion strings and checks smth
Let's imagine that I have list of files at host1 find /path/to -name *.jpg
Imagine I have a chunk of initialisation code at the top of a stored
What is the best way to organize the patch files? Imagine you have a
I'm desperately trying to solve this one. I have a bunch of files stored
I have two nib files, one that will open at startup and another that
I imagine my application like this: I have an application for encrypting files. And
I have file called common.js and it's included in each page of my site
Imagine I have a txt file with a path like: c:\programs\SRC_CODE\ How can I
Imagine I have the folling XML file: <a>before<b>middle</b>after</a> I want to convert it into

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.