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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:44:53+00:00 2026-05-12T20:44:53+00:00

I have a section of code like the following: —- file.php —- require_once(mylib.php); function($a,$b)

  • 0

I have a section of code like the following:

—- file.php —-

require_once("mylib.php");

function($a,$b)
{
    $r = $_GLOBALS['someGlobal'];
    echo $r;
}

—- mylib.php —-

$_GLOBALS['someGlobal'] = "Random String";

This is a bit trivialized, but is the exact problem I have an I haven’t found some related stuff, but nothing that answers my question directly.

When I call function($a,$b) nothing is echo’d, that is – $r is “empty” as if nothing was ever assigned to $_GLOBALS['someGlobal'];

In addition, I have tried with the following:

global $someGlobal;
$someGlobal = "Random String";

Same thing, no effect.
Also, in file.php if I try with global, or with just $someGlobal it still does not work.

As far as I know, from the documentation on php.net using global $someGlobal in mylib.php (and having that inserted in the top level of file.php) that it would not actually do much since it’s already at the “top-level” of the scope hierarchy as far as I can tell. However, I thought registering it as a global might allow it to be accessed from inside the function, but this is clearly not the case.

Can anybody explain why, and explain how to get around this?

Edit: I should not that in file.php if I use $_GLOBALS['someGlobal']; the value is recovered fine if it’s not in a function.

  • 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-12T20:44:53+00:00Added an answer on May 12, 2026 at 8:44 pm

    Wrong variable name. It’s $GLOBALS not $_GLOBALS

    http://www.php.net/manual/en/reserved.variables.globals.php

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

Sidebar

Ask A Question

Stats

  • Questions 217k
  • Answers 217k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer When a page is reloaded, any iframes contained in it… May 12, 2026 at 11:22 pm
  • Editorial Team
    Editorial Team added an answer It happens automatically. If your code calls the operators ==… May 12, 2026 at 11:22 pm
  • Editorial Team
    Editorial Team added an answer Pages of the innodb data files get cached in the… May 12, 2026 at 11:22 pm

Related Questions

I have a section of code like the following: ---- file.php ---- require_once(mylib.php); function($a,$b)
I am looking to create a user/server control that will be created with something
I have a MDI application written in Delphi 2007. If the user exits a
Hi guys wonder if you guys could help me I'm trying to compile a
I have a website built using Asp.net and LinqToSql for Data Access. In a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.