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

  • Home
  • SEARCH
  • 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 9004803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:58:57+00:00 2026-06-16T00:58:57+00:00

http://php.net/manual/en/language.oop5.properties.php shows the following example which fails for me. class SimpleClass{ private $var3 =

  • 0

http://php.net/manual/en/language.oop5.properties.php shows the following example which fails for me.

class SimpleClass{
   private $var3 = 1+2;
}

Parse error: syntax error, unexpected '+', expecting ',' or ';'....

Any ideas why?

php version 5.4.9

  • 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-06-16T00:58:58+00:00Added an answer on June 16, 2026 at 12:58 am

    The documentation never states that it is a valid property declaration. It specifically states its an invalid example.

    directly from your link

    <?php
    class SimpleClass
    {
       // invalid property declarations:
       public $var1 = 'hello ' . 'world';
       public $var2 = <<<EOD
    hello world
    EOD;
       public $var3 = 1+2;
       public $var4 = self::myStaticMethod();
       public $var5 = $myVar;
    
       // valid property declarations:
       public $var6 = myConstant;
       public $var7 = array(true, false);
    
       // This is allowed only in PHP 5.3.0 and later.
       public $var8 = <<<'EOD'
    hello world
    EOD;
    }
    ?>
    

    this is just how the language syntax is defined for PHP.

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

Sidebar

Related Questions

Referring to http://php.net/manual/en/language.oop5.static.php , Declaring class properties or methods as static makes them accessible
According to one of the man pages http://www.php.net/manual/en/language.oop5.static.php : Calling non-static methods statically generates
My question is rather simple, here is the context: http://php.net/manual/en/language.oop5.magic.php Magic Methods The function
I use Factories (see http://www.php.net/manual/en/language.oop5.patterns.php for the pattern) a lot to increase the testability
I am learning php and read this example in this http://www.php.net/manual/en/language.types.boolean.php tutorial, I want
Possible Duplicate: In PHP can someone explain cloning vs pointer reference? According to http://php.net/manual/en/language.oop5.references.php
I was looking for info about singleton pattern, I found: http://www.php.net/manual/en/language.oop5.patterns.php#95196 I don't understand:
According to http://php.net/manual/en/language.oop5.autoload.php the magic function __autoload() was deprecated as of PHP 7.2.0 and
I saw this in the PHP OOP manual http://www.php.net/manual/en/language.oop5.visibility.php and I can't get my
http://php.net/manual/en/mysqli.init.php $ConnectionResource = mysqli::init(); The above code fails with: Fatal error: Non-static method mysqli::init()

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.