Recommended resources for the second season of Li Yanhui's PHP video tutorial

黄舟
Release: 2023-03-15 16:14:01
Original
2671 people have browsed it

The video "Li Yanhui PHP Video Tutorial Season 2" is based on "Li Yanhui PHP Video Tutorial Season 1" to deepen the learning of PHP. This video introduces object-oriented thinking, practical membership registration and cms management system Explain in detail, through the study of these knowledge points, I believe everyone's strength will be significantly improved

Recommended resources for the second season of Li Yanhuis PHP video tutorial

Course playback address: http://www. php .cn/course/398.html

The teacher’s teaching style:

The teacher’s lectures are vivid, witty, witty, and touching. . A vivid metaphor is like the finishing touch, opening the door to wisdom for students; a well-placed humor brings a knowing smile to students, like drinking a glass of mellow wine, giving people aftertaste and nostalgia; a philosopher's aphorisms, cultural references Proverbs are interspersed from time to time in the narration, giving people thinking and warning.

The more difficult point in this video is object-oriented:

Encapsulation is one of the three major characteristics of object-oriented programming. Encapsulation is to encapsulate the object Properties and services are combined into an independent and identical unit, and the internal details of the object are hidden as much as possible. It contains two meanings:

1. Combine all the properties and all services of the object to form an indivisible Independent units (i.e. objects).

2. Information hiding, that is, hiding the internal details of the object as much as possible, forming a boundary (or forming a barrier) to the outside world, and only retaining a limited external interface to connect it with the outside world.

The reflection of the principle of encapsulation in software is: it requires that parts other than the object cannot access the internal data (properties) of the object at will, thereby effectively avoiding "cross-infection" of external errors and making it Software errors can be localized, greatly reducing the difficulty of error detection and troubleshooting.

Let’s use an example to illustrate. Suppose a person’s object has attributes such as age and salary. Such personal privacy attributes are not accessible to other people. If you don’t use encapsulation, Then others can get it if they want to know, but if you encapsulate it, others will have no way to obtain the encapsulated attributes. Unless you tell it yourself, others will have no way to get it.

For example, personal computers have a password, and you don’t want others to log in at will and copy and paste it into your computer. Also, for objects like people, the attributes of height and age can only be increased by oneself, and cannot be assigned values ​​arbitrarily by others, etc.

Use the private keyword to encapsulate properties and methods:

Original members:

Copy after login

Change to encapsulated form:

Copy after login

None Add any access control, the default is public and can be accessed from anywhere.

name . " 性别:" . $this->sex . " 我的年龄是:" . $this->age;  
    //在这里也可以访问私有方法  
    //$this->run();  
}
Copy after login

Because the member method say() is public, it is okay for us to call the say() method outside the class. Change the above code:

name赋初使值  
        $this->name = $name;  
        //通过构造方法传进来的$sex给私有成员属性$this->sex赋初使值  
        $this->sex = $sex;  
        //通过构造方法传进来的$age给私有成员属性$this->age赋初使值  
        $this->age = $age;  
    }  
  
    //这个人可以说话的方法, 说出自己的私有属性,在这里也可以访问私有方法  
    function say() {  
        echo "我的名子叫:" . $this->name . " 性别:" . $this->sex . " 我的年龄是:" . $this->age;  
    }  
}  
  
//通过构造方法创建3个对象$p1、p2、$p3,分别传入三个不同的实参为姓名、性别和年龄  
$p1 = new Person("张三", "男", 20);  
$p2 = new Person("李四", "女", 30);  
$p3 = new Person("王五", "男", 40);  
  
//下面访问$p1对象中的说话方法  
$p1->say();  
//下面访问$p2对象中的说话方法  
$p2->say();  
//下面访问$p3对象中的说话方法  
$p3->say();  
?>
Copy after login

Output result:

我的名子叫:张三 性别:男 我的年龄是:20我的名子叫:李四 性别:女 我的年龄是:30我的名子叫:王五 性别:男 我的年龄是:40
Copy after login

The above is the detailed content of Recommended resources for the second season of Li Yanhui's PHP video tutorial. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!