Object-oriented question: why is the hint undefined?

Source: Internet
Author: User
Is it because I did not add this ah I see people say if not add this is understood as a local variable inside the method of the sentence how to understand AH is not the error? So why do you get an error? I'm a novice, and I'm feeling object-oriented.


  
  who();?>

Reply content:

Is it because I did not add this ah I see people say if not add this is understood as a local variable inside the method of the sentence how to understand AH is not the error? So why do you get an error? I'm a novice, and I'm feeling object-oriented.


  
  who();?>

No add this can be recognized as a class variable that is the Java rule. The use of class variables in PHP must prefix this.

1, the Who method inside the $name is indeed an undefined variable, you can use Isset ($name) to determine whether the value of the variable is set.
2. The $name of the Who method does not add $this, but $name must be initialized!!! such as $name = ' Zhangsan '; echo $name; then $name is the local variable in the Who method.

3. The Who method adds $this, that is, Echo $this->name, then accesses the properties of the class.

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