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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:30:23+00:00 2026-05-31T01:30:23+00:00

Possible Duplicate: Syntax error while defining an array as a property of a class

  • 0

Possible Duplicate:
Syntax error while defining an array as a property of a class

I’m trying to do the following:

final class TestClass {
    public static $myvar = 10*10; //line 3
    //rest of code...
}

but i’m getting this error: syntax error, unexpected '*', expecting ',' or ';' [line 3]

why isn’t this possible? of course, if i change 10*10 to 100, everything works ok.
Is it not allowed to init a static variable with a math calculation? Not possible with any way?

  • 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-31T01:30:25+00:00Added an answer on May 31, 2026 at 1:30 am

    From php docs

    Like any other PHP static variable, static properties may only be initialized using a literal or constant; expressions are not allowed. So while you may initialize a static property to an integer or array (for instance), you may not initialize it to another variable, to a function return value, or to an object.

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

Sidebar

Related Questions

Possible Duplicate: Initializing PHP class property declarations with simple expressions yields syntax error Is
Possible Duplicate: Initializing PHP class property declarations with simple expressions yields syntax error Is
Possible Duplicate: declare property as object? class core { public $dbh = new PDO(mysql:dbname=newdbnaem;host=1.1.1.1:1111,
Possible Duplicate: Instance as a static class property I got a problem about creating
Possible Duplicate: Collection initialization syntax in Visual Basic 2008? How is the following C#
Possible Duplicate: Workaround for basic syntax not being parsed I am trying to allow
Possible Duplicate: Why does VS2010 give syntax errors when syntax is correct? I'm trying
Possible Duplicate: Cannot use concatenation when declaring default class properties in PHP? The following
Possible Duplicate: From the string name of a class, can I get a static
Possible Duplicate: Literal Syntax For byte[] arrays using Hex notation..? I am trying to

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.