PHP A class of weird questions??

Source: Internet
Author: User
PHP defines a class. Why the following first situation is not a problem, the second case of error??


  
   

Reply content:

PHP defines a class. Why the following first situation is not a problem, the second case of error??


  
    

  Class A {$    x = Array ();//Although this kind of writing is supported, but it is not recommended, should be written as public $x = Array (); private static $y = $x;//This is a very obvious syntax error, first here cannot use the variable, the second access property should be $this->x}  

Class static variables and constant declarations can not be used variables, is a syntax error. I think it's because the variables are not assigned when the object has no instances, so neither static variables nor constants can get valid values.
Recommendation:
1-Modify the php.ini to display the error message so that you do not see the dry 500 error, but the reason for the error of the PHP prompt, which helps to solve the problem
2-using the more professional PHP development IDE, Like Phpstorm or Zendstudio (I'm using this), this simple syntax error is directly red by the IDE.

Suggest you learn PHP grammar, write a syntax error code out, there is no weird problem is not weird.

What is contained in the class: Static methods and properties that are about classes The other is the object's (instance of the Class) method and property

Statically, of course, cannot directly invoke what belongs to the object (the object does not exist yet!!!

This is the basic concept of object-oriented ...

Foundation did not learn to write code directly, only to say that the abuse of their own life

  • 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.