Home > Article > Backend Development > Development ideas and case analysis of PHP object-oriented programming
In the process of learning PHP, object-oriented is an indispensable part. Many friends are ambiguous about object-oriented. To learn object-oriented, of course, we must first understand what a class is, what an object is, and what a class is. What does it have to do with the object? The relationship between classes and objects: A class is a template used to generate objects, and an object is an instance of a class. I believe everyone is familiar with this. Today we will introduce to you the development of PHP object-oriented programming!
The first step is to download the PHP object-oriented programming class library we need to use in this course: //m.sbmmt.com/xiazai/leiku/618
Step 2: After the download is completed, find the php class file we need, unzip it to our local directory, and create a new php file!
The third step, after completion, we need to call this class in the new php file and instantiate the class:
<?php include_once "dingyi3.php";//引入类文件 //实例化 $person1 = new Person (); $person2 = new Person ( "2" ); $person3 = new Person ( "3" ); // 自动调用了__set() $person1->name = "张三"; echo $person1->name; echo "<br/>"; echo $person1->say (); // 自动调用了__get() echo $person1->age; echo "<br/>"; var_dump ( isset ( $person1->name ) ); echo "<br/>"; unset($person1->name); echo "unset------------>".$person1->name;//name 没有被unset() echo "<br/>"; $person2 = null; ?>
Run the file, and the result will be as shown below:
The above is the detailed content of Development ideas and case analysis of PHP object-oriented programming. For more information, please follow other related articles on the PHP Chinese website!