PHP language knowledge class what is class _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
What is PHP knowledge class. LieHuo. net) before explaining the concept of classes, let's talk about the concept of object-oriented programming: Object-oriented programming (Object-OrientedProgramming, short for OOP) stands for the help House (www.Bkjia.com) before explaining the concept of classes, let's talk about the concept of object-oriented Programming: Object-oriented Programming (Object-Oriented Programming, short for OOP) is designed to create software to reuse code, it has the ability to better simulate the real world environment, which makes it recognized as the winner of top-down programming. It adds an extension statement to the program to encapsulate the function into the "object" necessary for programming. The object-oriented programming language makes complex work organized and easy to write. It is a revolution, not for the objects themselves, but for their ability to process their work. Objects are not compatible with traditional programming and programming methods, but some object-oriented objects make the situation worse. Unless the entire development environment is object-oriented, the benefits of the object have not brought much trouble. Some people may say that PHP is not a real object-oriented programming language. PHP is a hybrid language. you can use object-oriented programming or traditional procedural programming. However, for development of large projects, you may want to use pure object-oriented programming in PHP to declare classes, and in your project development, only objects and classes are used. As the project grows, it may be helpful to use object-oriented programming. object-oriented programming code is easy to maintain, easy to understand, and reuse. these are the basis of software engineering. Applying these concepts in Web-based projects will become the key to future website success.

An Object is an abstraction of certain things in the problem domain or implementation domain. it reflects the information that needs to be stored in the system and its role; it is the encapsulation body of a set of attributes and a group of services that have the right to operate on these attributes. Objects must be understood in two ways: objects in the real world to be processed by the system; objects that computers do not directly process, but are processed by computers, this computer representation is also called an object. Simply put, a person is an object, and a ruler is also an object. When these objects can be directly represented by data, we call them Attributes. the measurement unit of a ruler can be centimeter, meter, or foot. this measurement unit is the property of a ruler.

In PHP, we can define a Class, which refers to the set of variables and some functions that use these variables. PHP is a loose type language, so the type overload does not work, and the overload does not work by the number of parameters. Sometimes it is very good to overload constructors in the orientation, so that you can create objects using different methods (passing different numbers of parameters ). PHP is implemented through classes.

Reference content is as follows:
Class Class_name // In the object-oriented programming class, the first character of the class is used to uppercase and must comply with the naming rules of variables.
{

// Set of functions and variables

}
?>

In PHP, information is encapsulated through classes. in PHP, the syntax for defining classes is:

Reference content is as follows:
Class Student
{
Var $ str_Name; // name
Var $ str_Sex; // gender
Var $ int_Id; // student ID
Var $ int_English; // English score
Var $ int_maths; // Mathematical score
}
?>

When defining a class, you can define it according to your preferred format, but it is better to maintain a standard so that development will be more effective.

Data members are defined using the "var" declaration in the class. they have no type before assigning values to data members. A data member can be an integer, an Array, an associated Array, or an object.

The following is an example of a class definition:

This is a simple example of a very common definition class, used to show students' learning scores. the class name is Student, and the Student class contains the basic attributes of a Student: name, gender, student ID, English score, and math score.

  • Three pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • Next page

Digest (LieHuo. net) before explaining the concept of classes, let's talk about the concept of object-oriented Programming: Object-oriented Programming (Object-Oriented Programming, short for OOP...

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.