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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:09:54+00:00 2026-05-30T22:09:54+00:00

Edit: Made more clearer I have a problem with a variable disappearing between function

  • 0

Edit: Made more clearer

I have a problem with a variable disappearing between function calls

firstly I start here with $pid being an int taken from a JSON string

print "PID".$pid."\n";
$a['points'] = Algorithm::getpredictionForPlayer($pid);

I get the output ‘PID12’ which is how it should be

Next in the Algorithm::getpredictionForPlayer

static function getpredictionForPlayer($pid)
{

            print "PID2:  ".$pid."\n";
    $points =0;

    for ($i = 0; $i < 10; $i++)
    {
    print "algorithm: ".$pid."\n";
        $points += v4::predictPointsForPlayer($pid);
    }

    return intval($points/10);
}

Occasionally i get ‘PID2: 12’, but more often all that prints is ‘PID2: ‘
Is there a reason the variable would disappear during this time?

  • 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-30T22:09:55+00:00Added an answer on May 30, 2026 at 10:09 pm

    Your variable in the global scope is $pid yet you are passing $player_id into the function

    print "PID".$pid."\n";
    $a['points'] = Algorithm::getpredictionForPlayer($player_id);
    

    You’ve then got a parameter in your static method called $pid

    static function getpredictionForPlayer($pid)
    

    but this isn’t the same as the variable in your global scope. In fact this will take the same value as the $player_id that you are passing in. If you want the $pid variable from your global scope to exist in the static method you should pass it in instead of $player_id.

    btw, you should think about whether you really need a static method. Generally they make things hard to test and should be avoided if possible. Should you have a player object and call the method getPrediction() on that?

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

Sidebar

Related Questions

Edit: Maybe I made the question more complex than it should. My questions is
EDIT: I had made a mistake during the debugging session that lead me to
EDIT Taking COST 100 out made the command go through, however, I'm still unable
-edit- nevermind, i made a mistake in my select statement. Update was working correctly.
IMPORTANT EDIT: Sorry everyone, i made a big mistake in the structure. char *name;
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
I have been using telerik extensions for an asp.net mvc project, more specifically the
EDIT: Seems i didnt use an 'id' on my textarea, so that problem has
To make it more clear what I need to do, here is the structure

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.