I just browsed the article about Class updated on the homepage (referring to the http://www.phpe.net/articles/389.shtml of PHPE), very good, it is recommended to have a look.
Exploration of classes ~~ It took me half a year to understand the role and implementation of the class. There is not an article that can help me understand (I have never touched any OO stuff before ).
In my opinion, the Class used in PHP is an informal language and cannot be determined whether it is correct.
It is easy to create a class.
PHP code :--------------------------------------------------------------------------------
Class my_class {}
--------------------------------------------------------------------------------
What is the class? Many people use black boxes. Here I refer to them as an independent whole. We only know the class name, but do not know what is in it. So how should we use this class?
First, you need to know whether the public variable is defined in it-technically, it is called "attribute ".
Second, you need to know what function is defined in it-in professional terms, it is called "method ".
I am confused by these technical terms, so I simply ignore it.
How does one define public variables in a class?
It's easy. Let's expand the my_class class.
PHP code :--------------------------------------------------------------------------------
Class my_class
{
Var $ username;
}
--------------------------------------------------------------------------------
The above is simple. We have defined a public variable, which is composed of var + space + common variable names. What is its use? In the function, if we want to access variables outside the function, do we need to make a global operation first? The same is true for this purpose. It is used to allow all functions in this class to access it, and it is different from the function, and the variable can be accessed outside the class, I will talk about how to access it externally. Another difference is that you cannot assign values to this variable using complex statements (you can read the rules yourself after understanding the class ). Give it a default value
PHP code :--------------------------------------------------------------------------------
Class my_class
{
Var $ username = "deep space ";
}
--------------------------------------------------------------------------------
OK, defines a public variable, and then defines a function (that is, the so-called "method ").
PHP code :--------------------------------------------------------------------------------
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