In our process of learning PHP, object-oriented is an essential part, many small partners are ambiguous to object-oriented, learning object-oriented, of course, first of all to understand what is a class, what is the object, class and object what is the relationship? Class and object relationships: A class is a template used to build an object, and an object is an instance of a class. I believe this people have a better understanding, today we will introduce PHP object-oriented Programming development!
The first step is to download the PHP object-oriented Programming class library that we need to use for this lesson: http://www.php.cn/xiazai/leiku/618
The second step, after the download, find the PHP class files we need, unzip to our local directory, create a new PHP file!
After the third step, we will call this class in the new PHP file, and instantiate the class:
<?phpinclude_once "dingyi3.php";//Introduce class file//Instantiation $person1 = new Person (), $person 2 = new Person ("2"), $person 3 = new Perso N ("3");//__set () $person 1->name = "Zhang San"; Echo $person 1->name;echo "<br/>"; Echo $person 1->say ();//From __get () echo $person 1->age;echo "<br/>"; Var_dump (Isset ($person 1->name)); echo "<br/>"; unset ($ Person1->name); echo "unset------------>". $person 1->name;//name not been unset () echo "<br/>"; $person 2 = null;? >
Run the file and get the results as shown: