Some tips on Using Dynamic Web Technology in PHP-PHP source code

Source: Internet
Author: User
Ec (2); Exploring 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: What is the classmy_class {} class doing? Many people refer to it as a black box. Here I call it an independent whole. We only know the class name, but do not know script ec (2); script

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.

Creating a class is simple:

Class my_class {}

What is the class? Many people refer to it as a black box. Here I call it 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:

Class my_class
{
Var $ username;
}

The above is simple. We have defined a public variable, which is composed of common variables with var spaces. 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 allows all functions in this class to access it, and it is different from a function, is the external class can also access and control this variable at any time, 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:

Class my_class
{
Var $ username = "Deep Space ";
}

OK, defines a public variable, and then defines a function (that is, the so-called "method "):

Class my_class
{
Var $ username = "Deep Space ";

Function show_username ()
{
}
}

This definition function is no different from the normal definition function form. It's easy to define a function that prints $ username:

Class my_class
{
Var $ username = "Deep Space ";

Function show_username ($ username)
{
Echo $ username;
}
}

Some people may be confused here. There are now three $ usernames. Which is it ~~

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.