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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:22:12+00:00 2026-06-16T14:22:12+00:00

Just a quick question, but I’ve been working on a small MVC framework and

  • 0

Just a quick question, but I’ve been working on a small MVC framework and noticed something.

For example:

–PHP file–

class loadFiles{
        function __construct($file = NULL){
        include $file . '.php';
        }
}
$loadfiles = new $loadFiles('crucialsettings');
echo $randomstring; //Throws an error

–crucialsettings.php–

<?php
    $randomstring = 'hello';
?>

I only just realised that files included inside an objects scope are inaccessable from the global scope. What is the best way to include a file inside an object so it can be accessed globally?

I would like to be able to:

$loadfiles->settings();
$loadfiles->classes();
$loadfiles->passwords();

I want to build a class that handles global file includes.

  • 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-16T14:22:13+00:00Added an answer on June 16, 2026 at 2:22 pm

    It doesn’t matter where you include or require code from in PHP. The interpreter is pretty linear in it’s first definition pass, that is to say that it will basically compress all of the included / required files into one large file in the exact order in how it was read.

    One thing to note about this is that scope does change. but everything is applied to the “global” scope. You can always import something from the global scope into your current scope using the “global” keyword to declare a variable prior to using it. So when you want to use a “global” variable from another script just ask for it.

    A little example…

    a.php

    include('b.php');
    global $myVar;
    echo $myVar;
    

    b.php

    include('c.php');
    

    c.php

    $myVar = 'Hello World';
    

    What the interpreter see’s this code as after it’s first pass

    // In global scope
    $myVar = 'Hello World'
    
    // In a.php scope
    global $myVar;
    echo $myVar;
    

    In short from your php file simply add the line

    global $randomstring;
    

    After you include the crucialsettings.php file and your echo will work.

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

Sidebar

Related Questions

just a quick question about the mvc JqueryUI framework, i have a _layout.cshtml page
Just a really quick question about something small. The following is part of a
just a quick question, was trying different ways to accomplish this, but ended with
Just a quick question.. Following opening a text file in a separate definition (no
Just a quick question about best practice in MVC development. Let's say that I've
Just a quick question. I suppose I could just try it but I like
Just a quick question: There's the entity (for example User) who is connected with
Just a quick question: I'm working on revamping a script that serves vehicle inventory
Ok guys, just a quick question hopefully someone can find my mistake quickly, but
Just got a quick question, this is a simple thing to do via PHP

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.