Static variable assignment problem?

Source: Internet
Author: User
$a = 100;
static $b = $a;
Echo $b;

Why can't static variables be assigned to this value?


Reply to discussion (solution)

$b = 100;
static $a;
$a = $b;
echo $a;

Is that correct?

A static property can only be initialized to a character value or a constant and cannot use an expression.
You can static $a = ' a ', or $a=100 but cannot perform assignment operations or other expressions.

Static variables created during PHP precompilation
Therefore, you cannot assign a value to a normal variable because the normal variable is created at the subsequent run time

To put it bluntly, you can't assign a nonexistent value to a static variable.

A static variable cannot assign a value directly to another variable. After the declaration, it is not possible.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.