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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:52:11+00:00 2026-05-15T08:52:11+00:00

I have a function that gets a value from the database and returns it.

  • 0

I have a function that gets a value from the database and returns it. I call the function to store it into a member variable but I get the following error:

Parse error: parse error, expecting `','' or `';'' in I:\wamp\www\deposit\classes\Site.php on line 14

This is the line that causes the error

public static $depositmoney = self::get_balance();

And this is the function that gets the value from the database

    public static function get_balance()
    {
        global $link, $usertable, $userid, $useridentify;

        //query current balance
        $cb = mysqli_fetch_object(mysqli_query($link, "SELECT deposit FROM ".$usertable." WHERE ".$userid."=".$useridentify.""));
        return $cb->deposit;

    }//end of function get_balance().

all of this code is in the same class. Anyone an idea of what’s causing the error?

  • 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-15T08:52:12+00:00Added an answer on May 15, 2026 at 8:52 am

    Class properties may not be declared with run-time information.

    public static $depositmoney = self::get_balance();
    

    The above will not work.

    See the PHP Manual on Class Properties: (emphasis mine)

    Class member variables are called “properties”. You may also see them referred to using other terms such as “attributes” or “fields”, but for the purposes of this reference we will use “properties”. They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This declaration may include an initialization, but this initialization must be a constant value–that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

    You could create a getter for $depositmoney and have it initialize the value if it is currently unset:

    public static function getDepositMoney()
    {
        if(self::$depositmoney === NULL) {
            self::$depositmoney = self::get_balance();
        }
        return self::$depositmoney;
    }
    

    However, I suggest to get rid of the static and use instance methods and properties instead to track the state. You will also want to get rid of the global stuff and inject dependencies through the constructor, setters or during the method invocation. That decreases coupling and will make the code more maintainable.

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

Sidebar

Related Questions

I have a function that gets an int value from the user and assigns
So I have a function that gets some coordinates from a sql database and
In my Java code I have function that gets file from the client in
I have this function in jQuery that gets data from a page with POST,
I have a function that gets x(a value) and xs(a list) and removes all
Here's a brief rundown of my issue: I have a JavaScript function that gets
I have a function that sending a code gets a description through various formatings,
I have a function that returns two values in a list. Both values need
i am going to call a function which will retrieve some data value from
I have a function, that gets a large XML file, then parses it, and

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.