search
HomeBackend DevelopmentPHP TutorialRecommended resources for the second season of Li Yanhui's PHP video tutorial

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:

<?php  
var $name; //声明人的姓名  
var $sex; //声明人的性别  
var $age; //声明人的年龄  
function run(){……}

Change to encapsulated form:

<?php  
private $name; //把人的姓名使用private关键字进行封装  
private $sex; //把人的性别使用private关键字进行封装  
private $age; //把人的年龄使用private关键字进行封装  
private function run(){……} //把人的走路方法使用private关键字进行封装

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

<?php  
//这个人可以说话的方法, 说出自己的私有属性,在这里也可以访问私有方法  
function say() {  
    echo "我的名子叫:" . $this->name . " 性别:" . $this->sex . " 我的年龄是:" . $this->age;  
    //在这里也可以访问私有方法  
    //$this->run();  
}

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

<?php  
class Person  
{  
    //下面是人的成员属性  
    private $name; //人的名子,被private封装上了  
    private $sex; //人的性别, 被private封装上了  
    private $age; //人的年龄, 被private封装上了  
  
    //定义一个构造方法参数为私有的属性姓名$name、性别$sex和年龄$age进行赋值  
    function __construct($name, $sex, $age) {  
        //通过构造方法传进来的$name给私有成员属性$this->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();  
?>

Output result:

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

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!

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
How does Dependency Injection and a Service Container work in a modern PHP framework?How does Dependency Injection and a Service Container work in a modern PHP framework?Aug 14, 2025 pm 12:24 PM

DependencyInjection(DI)isadesignpatternwhereobjectsreceivetheirdependenciesfromoutsideratherthancreatingtheminternally,promotingloosecoupling,testability,andmaintainability.1.InsteadofhardcodingdependencieslikenewFileLogger()insideaclass,DIpassesthem

Summarize the TIME type fields in MySQL and format the outputSummarize the TIME type fields in MySQL and format the outputAug 14, 2025 am 11:51 AM

This article aims to solve the problem of summing TIME type fields in MySQL database and formatting output. By converting the TIME type to seconds for summing, then converting the total number of seconds back to the TIME type, and providing corresponding SQL examples to help developers correctly handle such time calculation requirements.

Customize product loops with WooCommerce meta_queryCustomize product loops with WooCommerce meta_queryAug 13, 2025 pm 06:33 PM

This document is intended to guide developers how to use the woocommerce_product_query hook to dynamically filter WooCommerce product loops based on the value of the custom meta field. Through the sample code, we will demonstrate how to filter products matching the book_age_group meta field based on the value of the URL parameter filterbyAge, and provide detailed implementation steps and precautions to help developers flexibly customize WooCommerce product display.

How to correctly add data to an arrayHow to correctly add data to an arrayAug 13, 2025 pm 06:27 PM

This article aims to guide developers how to correctly add data to PHP arrays to build JSON format data that conforms to a specific structure. Through the example code, we will demonstrate how to create an array containing the prices keys and add multiple associative arrays containing offer_id and price to the array corresponding to the prices keys, and finally generate the expected JSON output.

Laravel Excel exports empty files: data export practices and problem solving based on conditional filteringLaravel Excel exports empty files: data export practices and problem solving based on conditional filteringAug 13, 2025 pm 06:18 PM

This article deeply explores the problem of exporting empty files that may be encountered in Laravel applications when using the Maatwebsite/Laravel-Excel library for conditional filtering data export. The core reasons are usually the inappropriate request method (GET vs POST) and the misuse of the data parameter delivery mechanism. The article will provide a complete set of solutions, including code optimization for routing, views, controllers and export classes, to ensure that data filtering conditions are correctly passed and target data is exported successfully.

Filter by age WooCommerce Products: Custom Product Query TutorialFilter by age WooCommerce Products: Custom Product Query TutorialAug 13, 2025 pm 06:15 PM

This tutorial is intended to help developers realize the ability to filter products based on URL parameters in the WooCommerce product page loop. By using the woocommerce_product_query hook, we can modify the default product query and add a custom meta query to enable filtering based on product age. This tutorial provides detailed code examples and explains how to properly merge meta query to avoid overwriting the original query criteria.

Direct selection of specific printers for PHP/HTML web pages: technical limitation analysisDirect selection of specific printers for PHP/HTML web pages: technical limitation analysisAug 13, 2025 pm 06:12 PM

This article aims to clarify the technical limitations of printing directly by PHP or HTML on a web page. The core point is that due to PHP's server-side features and strict security policies of the browser and operating system, web pages cannot bypass the user's printing dialog box and directly select or force the use of non-default printers. All printing operations require manual confirmation by the user to ensure security and user control.

Laravel Excel solution to export blank filesLaravel Excel solution to export blank filesAug 13, 2025 pm 06:03 PM

This article aims to resolve common problems in Laravel where blank files appear when exporting Excel files using the maatwebsite/excel extension package. By modifying the routes, views, and controllers, and adjusting the Excel export class, ensuring that the parameters are correctly passed and the query is executed, ultimately achieving successful export of data. This article provides detailed code examples and steps to help developers quickly locate and solve problems.

See all articles

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.