Home  >  Article  >  Backend Development  >  Development ideas and case analysis of PHP object-oriented programming

Development ideas and case analysis of PHP object-oriented programming

黄舟
黄舟Original
2017-08-17 10:28:192704browse

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:

Development ideas and case analysis of PHP object-oriented programming

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn