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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:41:46+00:00 2026-06-18T07:41:46+00:00

If I have a file a.php which I can’t edit. <?php $a = 1;

  • 0

If I have a file a.php which I can’t edit.

<?php
$a = 1;
function a() {
  global $a;
  echo $a;
}  
a();

then running php a.php prints 1 nicely. But if I have b.php:

<?php
function b() {
  include "a.php";
}
b();

Then running php b.php doesn’t print anything.

What can I type before the include "a.php" to make it behave the same without editing a.php?

(Obviously other than defining $a. In my real-world example it has to work for a complicated a.php).

  • 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-18T07:41:47+00:00Added an answer on June 18, 2026 at 7:41 am

    It sounds like a.php is some legacy or 3rd party script that you have to wrap in your own application. I had a similar problem once and the solution was not pretty. First, you will have to find out, what global variables exist (grep global or similar helps).

    This is the relevant part of my “Script Adapter” class:

    private function _includeScript($file, $globals)
    {
        foreach ($globals as $global) {
            global $$global;
        }
    
        ob_start();
        require $file;
        $this->_response->setBody(ob_get_clean());
    }
    

    As you see, I had to catch the output too. The class also emulates $_GET and catches header calls to assign everything to a Response object, but for your case only this method is important. It gets called with the file name and an array of global variable names as parameters:

    _includeScript('a.php', array('a'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file which has some variables like $name1, $name2... How can
I have a file which is combination of PHP and HTML. How can i
I have an error.php file which can be grossly simplified to: <? if (!isset($error))
In my PHP/jQuery application, I have a javascript file, in which I can call
I want to have one file from which PHP can source content text such
I have a file PHP01.php which: - performs a function - creates an array
I'm trying to create a php file which I can edit straight away without
I have a php file which contains php function. I have to receive its
i have a php file which stores a variable, and i need to create
I have a php file which checks for login and password from users database,

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.