Php Tutorial: Amazing static attributes

Source: Internet
Author: User
This afternoon, an entry-level PHPER who fell in love with PHP at first sight asked me: what does it mean. I wrote this simple basic tutorial by the way. : Actually, it is a way to call static methods or static variables: Let's say, generally, if we encapsulate a variable or method into a Class, we cannot directly

This afternoon, an entry-level PHPER who fell in love with PHP at first sight asked me: what does it mean. I wrote this simple basic tutorial by the way. : Actually, it is a way to call static methods or static variables: Let's say, generally, if we encapsulate a variable or method into a Class, we cannot directly

This afternoon, an entry-level PHPER who fell in love with PHP at first sight asked me: what does it mean. I wrote this simple basic tutorial by the way. : Actually, it is a way to call static methods or static variables: Let's say, generally, if we encapsulate a variable or method into a Class, we cannot directly call this method or variable. I don't need to talk about anything nonsense. Let's look at the code to explain it.

You cannot directly call variables or classes.
 ??

If we write this way, an error will be reported immediately: the reason is that the $ itluren variable is not successfully called externally (but it is not because of him), __itluren () method cannot be called correctly, the _ itluren () function is not defined. To work properly, we need to instantiate this Class, which is the same as the next example.

Called after instantiation
 $ Itluren ))? 'EMPTY ': 'loving ';?? $ Itluren_class->__ itluren ();???? ???> ??

In this way, we can see the words "Love itluren.com. What is static for? Let's take a look at the following example !!

Static is playing.
 ??

We use echo (empty (example: $ itluren) separately ))? 'Null ': 'love'. Here, we can only see "love', because: We successfully called $ itluren to introduce a variable, and used example :: __itluren (); an error is indeed reported because the static attribute is not set for the _ itluren () method. Therefore, the call is successful through. How are you doing?

In general, we rarely encounter the static attribute, which is usually used when defining classes. However, this is also a very critical keyword, but exception is important, so we need to be clear. If you still don't understand it, we suggest you do it several times !!

Statement: This article uses BY-NC-SA protocol for authorization | IT passers-
Reprinted please note

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.