This article to introduce to you in the PHP object-oriented use of some of the details, here is mainly about the class in PHP, object learning notes, I hope you can help the students.
Object Oriented thinking
Object-Oriented programming (Object-oriented Programming,oop) is a programming paradigm, and colleagues are also a program development method. It takes the object as the basic unit of the program, encapsulates the program and data to improve the reusability, flexibility, and scalability of the software.
Process-oriented, object-oriented, and functional programming are known as the three Paradigms in programming languages (in fact, process-oriented and object-orientated are both imperative programming), and are three different coding and design styles. The object-oriented core idea is Object, encapsulation, reusability and extensibility.
Object-oriented is a more advanced, more abstract way of thinking, although the process is also an abstraction, but the process-oriented is a basic abstraction, object-oriented is based on the process of higher-level abstraction, so object-oriented understanding is not so easy.
Class is a description of a group of objects in our team
In PHP, each class is defined by the keyword class, followed by the class name, followed by a pair of curly braces, containing the definition of the class member and method. As shown in the following code
The code is as follows |
Copy Code |
Class person{ Public $name; Public $gender; Public function say () { echo $this->name. " Is ". $this->gender; } } |
You can then create an instance of this class:
The code is as follows |
Copy Code |
$student = new Person (); $student->name= "Tome"; $student->gender= "Male"; $student->say (); $teacher = new Person (); $teacher->name= "Kati"; $teacher->gender= "female"; $teacher->say (); |
This code instantiates the person class, resulting in an instance of the student object and the teacher object. It's actually the process from abstraction to concrete.
Some understanding of classes and objects:
The class defines a series of properties and methods, and provides practical details of the operations that can be used to process attributes.
The object contains the concrete value of the class property, which is the instantiation of the class. It is because of the different attributes that different objects can be distinguished. In the example above, because the sex and name of student and teacher are different, only two people can be separated.
The relationship between a class and an object is similar to a service being serviced, processed, and processed, and, in particular, the relationship between raw materials and pipelines. Only the methods that exist in the class are called on the object, and the properties of the class can be machined and its functions displayed.
Printing Student Objects
The code is as follows |
Copy Code |
Print_r ((array) $student); Var_dump ($student); |
Serializing objects
The code is as follows |
Copy Code |
$str = serialize ($student); Echo $str; File_put_contents (' Store.txt ', $str); Output Result: 0:6: "Person": 2:{s:4: "Name"; S:3: "Tom"; s:6: "Gender"; s:4: "Mail";} |
Deserializing objects
The code is as follows |
Copy Code |
$str = file_get_contents (' store.txt '); $student = Unserialize ($STR); $student->say (); |
http://www.bkjia.com/PHPjc/632678.html www.bkjia.com true http://www.bkjia.com/PHPjc/632678.html techarticle this article to introduce to you in the PHP object-oriented use of some of the details, here is mainly about the class in PHP, object learning notes, I hope you can help the students. Object-oriented thinking ...