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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:50:00+00:00 2026-05-26T01:50:00+00:00

I can not access the global variable in function in included file sample files

  • 0

I can not access the global variable in function in included file

sample files : dl.dropbox.com/u/9486036/similasyon.zip

simulations:

index.php:

<?

function init(){
    include "init.php";
}

init();

?>

init.php:

<?

$data = "data_string";

echo "Data-test in ".__FILE__.": <b>".$data."</b><br />\r\n"; 

include "php/funcs.php";

?>

funcs.php:

<? 

echo "Data-test in ".__FILE__.": <b>".$data."</b><br />\r\n";

function func_load()
{
    global $data;
    echo "Data-test in ".__FILE__." in function func_load(): <b>".$data."</b><br />\r\n";

    include dirname(__FILE__)."/funcs/sub_func.php";
}

func_load();

?>

sub_func.php:

<? 
    echo "Data-test in ".__FILE__.": <b>".$data."</b><br />\r\n";
?>

screen output:

Data-test in \similasyon\init.php                             : data_string 
Data-test in \similasyon\php\funcs.php                        : data_string 
Data-test in \similasyon\php\funcs.php in function func_load():  
Data-test in \similasyon\php\funcs\sub_func.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-05-26T01:50:01+00:00Added an answer on May 26, 2026 at 1:50 am

    That is because the initial include is also wrapped in a function and the would need a global $data inside it like this in your index.php

     function init(){
          global $data;
          include "init.php";
     }
     init();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I access a users microphone in Python? Sorry I forgot not everyone is
Anyone know a tool I can use to debug cannot access the file because
I am trying to access variable 'dimensions' in my ajax response but not able
It seems that i cannot access $(this) inside jquery ajax success function. please see
kt@rails-ubuntu:~/rails/ledger/releases/20080820144914/.git/hooks$ ls -al ls: cannot access post-commit: No such file or directory ls: cannot
I am getting a pretty common, The process cannot access the file because it
The following code does not compile, saying error C2248: 'A::getMe' : cannot access private
Assuming that the mysqli object is already instantiatied (and connected) with the global variable
I have a module containing multiple global functions, and a global variable. The variable
Every global variable in javascript is a property of 'window' Apparently all local variable

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.