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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:24:53+00:00 2026-05-31T03:24:53+00:00

I have a problem with the below:- //index.php <?php define(‘PATH’,’Ajfit/’); /* Get all the

  • 0

I have a problem with the below:-

//index.php
<?php

define('PATH','Ajfit/');

/* Get all the required files and functions */
require(PATH . 'settings.inc.php');
require(PATH . 'inc/common.inc.php');

?>

//setting.inc.php
<?php
      $settings['language']='English';
?>

//inc/common.inc.php
<?php
      //global $settings, $lang, $_SESSION; //$setting = null????
      $language = $settings['language']; //$language is still null
?>

when i try and access the global variable $settings within common.inc.php it is set null even though i set the variable within setting.inc.php. If i debug, when i step out of setting.inc.php the $settings valiable is set within the index.php, however when i step into common.inc.php the $settings valiable is set to null.

Does anyone have any ideas?

  • 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-31T03:24:55+00:00Added an answer on May 31, 2026 at 3:24 am

    Answer: In the inc/common.inc.php file, you don’t need to use the global keyword, the variable is already accessible. Using global redefines the variable, and is thus made null.

    Explanation:

    Variable Scope is the key here. The global keyword is only required when scope changes. The scope of regular files (including include()s) is all the same, so all of your variables are accessible by any php in the same scope, even if it comes from a different file.

    An example of where you need to use global is inside of functions. The scope of a function is different than that of plain php, which is different from class scope, and so on.

    Example:

    //foo.php
      $foo = "bar";
    
      echo $foo; //prints "bar" since scope hasn't changed.
    
      function zoo() {
        echo $foo; //prints "" because of scope change.
      }
    
      function zoo2() {
        global $foo;
        echo $foo; //prints "bar" because $foo is recognized as in a higher scope.
      }
    
      include('bar.php');
    
    //bar.php
      echo $foo; //prints "bar" because scope still hasn't changed.
    
      function zoo3() {
        echo $foo; //prints "" for the same reason as in zoo()
      }
    
      function zoo4() {
        global $foo;
        echo $foo; //prints "bar" for the same reason as in zoo2()
      }
    

    More Information:

    If you want more information on when to use global and when not to, check the php.net documentation on variable scope.

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

Sidebar

Related Questions

I have a link with 'remove' anchor text with href something like below: ./index.php?del_id=5
I have these three files to work with: document_root/include/config.php document_root/include/database.php document_root/index.php And the relevant
Solution to original problem (below) may have been discovered. I commented out <identity> ...
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
I have a problem with the SQL statement detailed below. The query returns the
I have a problem for querying records into mysql explanation below The user could
I have a problem when trying to execute this update statement (below) using C#
I have a problem with a template and pointers ( I think ). Below
I have some problem with my cfml website. I have used the below code
I have the same problem as described in the posts listed below. That is,

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.