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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:54:14+00:00 2026-05-29T05:54:14+00:00

Scenario: there is a global array $cache . there is 1 function, cacheWriter() ,

  • 0

Scenario:

  1. there is a global array $cache.
  2. there is 1 function, cacheWriter(), that updates $cache with
    various cachable objects. cacheWriter() runs a switch() with
    different cases that each update a certain key in $cache.
  3. some cases in cacheWriter() depend on other cases to correctly
    update $cache. In these cases, the script checks if the array key
    it depends on already exists in $cache, and if not, it will call
    cacheWriter() from within to get the case it needs.

In these cases, will $cache already be updated and contain the new content, or only the next time the function runs?

Example:

function cacheWriter($case) {
    global $cache;

    if($cache[$case]) {
        $out = $cache[$case];

    } else {

        switch($case) {
            case 1 : 
                $cache[1] = 'some object';
            break;

            case 2 :
                if(!$cache[1]) {
                    $dummy = cacheWriter(1);
                }

                //QUESTION:
                //will $cache[1] now exist right here (since it's global)
                //so that I can now simply access it like this:

                $cache[2] = $cache[1]->xyz;

                //OR,
                //do I have to use $dummy to get [1]
                //and $cache[1] will only exist the next time the function runs?            

            break;
        }

        $out = $cache[$case];
    }

    return $out;

}//cacheWriter()

Obviously, this function is extremely simplified, but it’s the basic concept. Thanks!

  • 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-29T05:54:15+00:00Added an answer on May 29, 2026 at 5:54 am

    Yes, the value of the global will contain the last write. The global directive is for scoping purposes, to tell the interpreter which variable to use – it doesn’t actually “import” the value and hold onto it at that point.

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

Sidebar

Related Questions

Scenario : There is this online questionaire that will be filled in by various
Are there any security exploits that could occur in this scenario: eval(repr(unsanitized_user_input), {__builtins__: None},
I have a question about global.asax that I don't really understand. My scenario is
We all know that global variables are anything but best practice. But there are
this must be such a common scenario that there's been a lot written about
Here is the simple scenario that I want to apply; There is a .NET
I have the following scenario: there are a database that generates a new logTable
Is there a particular scenario where a WriteOnly property makes more sense then a
There is a scenario where an application tells a device on a network to
How would the following scenario best be implemented: There is a standardized user interface

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.